From df5d0bacd63ec31898584208003b7948fe7b3182 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 5 Sep 2012 11:45:07 -0400
Subject: [PATCH] Changed recommendation interface in preparation for service
 locator integration.

---
 module/VuFind/src/VuFind/Recommend/AuthorFacets.php  |  8 +++++---
 module/VuFind/src/VuFind/Recommend/AuthorInfo.php    |  8 +++++---
 .../src/VuFind/Recommend/AuthorityRecommend.php      |  8 +++++---
 .../VuFind/src/VuFind/Recommend/EuropeanaResults.php |  8 +++++---
 .../VuFind/Recommend/EuropeanaResultsDeferred.php    |  8 +++++---
 module/VuFind/src/VuFind/Recommend/ExpandFacets.php  |  8 +++++---
 .../VuFind/src/VuFind/Recommend/FavoriteFacets.php   |  8 +++++---
 .../src/VuFind/Recommend/OpenLibrarySubjects.php     |  8 +++++---
 .../VuFind/Recommend/OpenLibrarySubjectsDeferred.php |  8 +++++---
 .../VuFind/src/VuFind/Recommend/PubDateVisAjax.php   |  8 +++++---
 .../src/VuFind/Recommend/RecommendInterface.php      |  8 +++++---
 .../src/VuFind/Recommend/ResultGoogleMapAjax.php     |  8 +++++---
 module/VuFind/src/VuFind/Recommend/SearchObject.php  |  8 +++++---
 module/VuFind/src/VuFind/Recommend/SideFacets.php    |  8 +++++---
 .../VuFind/src/VuFind/Recommend/SummonDatabases.php  | 12 +++++++-----
 module/VuFind/src/VuFind/Recommend/SwitchType.php    | 10 ++++------
 module/VuFind/src/VuFind/Recommend/TopFacets.php     | 12 +++++++-----
 .../src/VuFind/Recommend/WorldCatIdentities.php      |  8 +++++---
 module/VuFind/src/VuFind/Recommend/WorldCatTerms.php | 10 ++++++----
 module/VuFind/src/VuFind/Search/Base/Params.php      |  3 ++-
 20 files changed, 101 insertions(+), 66 deletions(-)

diff --git a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
index 3233bce2b56..8a96c93ef08 100644
--- a/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/AuthorFacets.php
@@ -51,13 +51,15 @@ class AuthorFacets implements RecommendInterface
     protected $searchObject;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Save the basic parameters:
         $this->settings = $settings;
diff --git a/module/VuFind/src/VuFind/Recommend/AuthorInfo.php b/module/VuFind/src/VuFind/Recommend/AuthorInfo.php
index bc54993900c..8f9d68f3aae 100644
--- a/module/VuFind/src/VuFind/Recommend/AuthorInfo.php
+++ b/module/VuFind/src/VuFind/Recommend/AuthorInfo.php
@@ -48,13 +48,15 @@ class AuthorInfo implements RecommendInterface
     protected $lang;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $translator = Translator::getTranslator();
         $this->lang = is_object($translator) ? $translator->getLocale() : 'en';
diff --git a/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php b/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
index ab8fdd2e94c..e68c1558b35 100644
--- a/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
+++ b/module/VuFind/src/VuFind/Recommend/AuthorityRecommend.php
@@ -58,13 +58,15 @@ class AuthorityRecommend implements RecommendInterface
     protected $results = array();
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $params = explode(':', $settings);
         for ($i = 0; $i < count($params); $i += 2) {
diff --git a/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php b/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php
index 8e21fe248d8..c57d644de79 100644
--- a/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php
+++ b/module/VuFind/src/VuFind/Recommend/EuropeanaResults.php
@@ -55,13 +55,15 @@ class EuropeanaResults implements RecommendInterface
     protected $results;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Parse out parameters:
         $params = explode(':', $settings);
diff --git a/module/VuFind/src/VuFind/Recommend/EuropeanaResultsDeferred.php b/module/VuFind/src/VuFind/Recommend/EuropeanaResultsDeferred.php
index 0691eb35d0e..e4afb7ccd22 100644
--- a/module/VuFind/src/VuFind/Recommend/EuropeanaResultsDeferred.php
+++ b/module/VuFind/src/VuFind/Recommend/EuropeanaResultsDeferred.php
@@ -47,13 +47,15 @@ class EuropeanaResultsDeferred implements RecommendInterface
     protected $processedParams;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $this->rawParams = $settings;
     }
diff --git a/module/VuFind/src/VuFind/Recommend/ExpandFacets.php b/module/VuFind/src/VuFind/Recommend/ExpandFacets.php
index 0baa798bb1c..16a8f7151fc 100644
--- a/module/VuFind/src/VuFind/Recommend/ExpandFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/ExpandFacets.php
@@ -44,13 +44,15 @@ class ExpandFacets implements RecommendInterface
     protected $searchObject;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Save the basic parameters:
         $this->settings = $settings;
diff --git a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
index a05df435463..69a050f56de 100644
--- a/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/FavoriteFacets.php
@@ -41,13 +41,15 @@ namespace VuFind\Recommend;
 class FavoriteFacets extends SideFacets
 {
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $this->mainFacets = array('lists' => 'Your Lists', 'tags' => 'Your Tags');
     }
diff --git a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php
index 23ffe6e81c7..02765da8a31 100644
--- a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php
+++ b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjects.php
@@ -53,13 +53,15 @@ class OpenLibrarySubjects implements RecommendInterface
     protected $result = false;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Parse out parameters:
         $params = explode(':', $settings);
diff --git a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjectsDeferred.php b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjectsDeferred.php
index a69a8e8b8ae..bed5ccdb8dc 100644
--- a/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjectsDeferred.php
+++ b/module/VuFind/src/VuFind/Recommend/OpenLibrarySubjectsDeferred.php
@@ -47,13 +47,15 @@ class OpenLibrarySubjectsDeferred extends OpenLibrarySubjects
     protected $processedParams;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $this->rawParams = $settings;
     }
diff --git a/module/VuFind/src/VuFind/Recommend/PubDateVisAjax.php b/module/VuFind/src/VuFind/Recommend/PubDateVisAjax.php
index c952267799e..110333c59ee 100644
--- a/module/VuFind/src/VuFind/Recommend/PubDateVisAjax.php
+++ b/module/VuFind/src/VuFind/Recommend/PubDateVisAjax.php
@@ -47,13 +47,15 @@ class PubDateVisAjax implements RecommendInterface
     protected $dateFacets = array();
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Save the basic parameters:
         $this->settings = $settings;
diff --git a/module/VuFind/src/VuFind/Recommend/RecommendInterface.php b/module/VuFind/src/VuFind/Recommend/RecommendInterface.php
index 034c6141ed0..47a3e59b09e 100644
--- a/module/VuFind/src/VuFind/Recommend/RecommendInterface.php
+++ b/module/VuFind/src/VuFind/Recommend/RecommendInterface.php
@@ -49,13 +49,15 @@ namespace VuFind\Recommend;
 interface RecommendInterface
 {
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings);
+    public function setConfig($settings);
 
     /**
      * init
diff --git a/module/VuFind/src/VuFind/Recommend/ResultGoogleMapAjax.php b/module/VuFind/src/VuFind/Recommend/ResultGoogleMapAjax.php
index ec4879b65f2..3b27714378e 100644
--- a/module/VuFind/src/VuFind/Recommend/ResultGoogleMapAjax.php
+++ b/module/VuFind/src/VuFind/Recommend/ResultGoogleMapAjax.php
@@ -47,13 +47,15 @@ class ResultGoogleMapAjax implements RecommendInterface
     protected $searchObject;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // No special settings
     }
diff --git a/module/VuFind/src/VuFind/Recommend/SearchObject.php b/module/VuFind/src/VuFind/Recommend/SearchObject.php
index 8f0409b2488..7c78ecd6bd0 100644
--- a/module/VuFind/src/VuFind/Recommend/SearchObject.php
+++ b/module/VuFind/src/VuFind/Recommend/SearchObject.php
@@ -45,13 +45,15 @@ abstract class SearchObject implements RecommendInterface
     protected $requestParam;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $settings = explode(':', $settings);
         $this->requestParam = empty($settings[0]) ? 'lookfor' : $settings[0];
diff --git a/module/VuFind/src/VuFind/Recommend/SideFacets.php b/module/VuFind/src/VuFind/Recommend/SideFacets.php
index 1ed92c9afc8..9460e96c322 100644
--- a/module/VuFind/src/VuFind/Recommend/SideFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/SideFacets.php
@@ -47,13 +47,15 @@ class SideFacets implements RecommendInterface
     protected $results;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Parse the additional settings:
         $settings = explode(':', $settings);
diff --git a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
index b5fabcfcc06..6a01be66bac 100644
--- a/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
+++ b/module/VuFind/src/VuFind/Recommend/SummonDatabases.php
@@ -43,21 +43,23 @@ use VuFind\Search\Summon\Params as SummonParams,
 class SummonDatabases implements RecommendInterface
 {
     protected $databases;
-    protected $requestParam;
+    protected $requestParam = 'lookfor';
     protected $lookfor;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Only one setting -- HTTP request field containing search terms (ignored
         // if $searchObject is Summon type).
-        $this->requestParam = empty($settings) ? 'lookfor' : $settings;
+        $this->requestParam = empty($settings) ? $this->requestParam : $settings;
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Recommend/SwitchType.php b/module/VuFind/src/VuFind/Recommend/SwitchType.php
index 4753020aeb6..85c080511a5 100644
--- a/module/VuFind/src/VuFind/Recommend/SwitchType.php
+++ b/module/VuFind/src/VuFind/Recommend/SwitchType.php
@@ -47,17 +47,15 @@ class SwitchType implements RecommendInterface
     protected $active;          // is this module active?
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
      *
-     * TopFacets:[ini section]:[ini name]
-     *      Display facets listed in the specified section of the specified ini file;
-     *      if [ini name] is left out, it defaults to "facets."
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $params = explode(':', $settings);
         $this->newHandler = !empty($params[0]) ? $params[0] : 'AllFields';
diff --git a/module/VuFind/src/VuFind/Recommend/TopFacets.php b/module/VuFind/src/VuFind/Recommend/TopFacets.php
index 9306a7dd770..304848eb8e3 100644
--- a/module/VuFind/src/VuFind/Recommend/TopFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/TopFacets.php
@@ -48,17 +48,19 @@ class TopFacets implements RecommendInterface
     protected $results;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
-     *
-     * @param string $settings Settings from searches.ini.
+     * Store the configuration of the recommendation module.
      *
      * TopFacets:[ini section]:[ini name]
      *      Display facets listed in the specified section of the specified ini file;
      *      if [ini name] is left out, it defaults to "facets."
+     *
+     * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         $settings = explode(':', $settings);
         $mainSection = empty($settings[0]) ? 'ResultsTop':$settings[0];
diff --git a/module/VuFind/src/VuFind/Recommend/WorldCatIdentities.php b/module/VuFind/src/VuFind/Recommend/WorldCatIdentities.php
index 7f80a48cc5f..13d38630276 100644
--- a/module/VuFind/src/VuFind/Recommend/WorldCatIdentities.php
+++ b/module/VuFind/src/VuFind/Recommend/WorldCatIdentities.php
@@ -45,13 +45,15 @@ class WorldCatIdentities implements RecommendInterface
     protected $settings;
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Save the basic parameters:
         $this->settings = $settings;
diff --git a/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php b/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php
index 9c8884d4a80..58bc4c3844e 100644
--- a/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php
+++ b/module/VuFind/src/VuFind/Recommend/WorldCatTerms.php
@@ -42,16 +42,18 @@ use VuFind\Connection\WorldCatUtils;
 class WorldCatTerms implements RecommendInterface
 {
     protected $searchObject;
-    protected $vocab;
+    protected $vocab = 'lcsh';
 
     /**
-     * Constructor
+     * setConfig
      *
-     * Establishes base settings for making recommendations.
+     * Store the configuration of the recommendation module.
      *
      * @param string $settings Settings from searches.ini.
+     *
+     * @return void
      */
-    public function __construct($settings)
+    public function setConfig($settings)
     {
         // Pick a vocabulary (either user-specified, or LCSH by default):
         $params = trim($settings);
diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php
index 5d73d9b8a73..3040edc274b 100644
--- a/module/VuFind/src/VuFind/Search/Base/Params.php
+++ b/module/VuFind/src/VuFind/Search/Base/Params.php
@@ -818,7 +818,8 @@ class Params implements ServiceLocatorAwareInterface
 
                 // Build a recommendation module with the provided settings.
                 if (class_exists($class)) {
-                    $obj = new $class($params);
+                    $obj = new $class();
+                    $obj->setConfig($params);
                     $obj->init($this, $request);
                     $this->recommend[$location][] = $obj;
                 } else {
-- 
GitLab