From a5b9abcac9a9f466f6b92a41f4928812b5f3b717 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 26 Apr 2017 15:33:33 -0400
Subject: [PATCH] Refactored SpellingSuggestions to use
 AbstractResultsPassthrough. - This new abstract base class makes it easy to
 create modules that only need to display a template based on the results
 object.

---
 .../Recommend/AbstractResultsPassthrough.php  | 104 ++++++++++++++++++
 .../VuFind/Recommend/SpellingSuggestions.php  |  60 +---------
 2 files changed, 105 insertions(+), 59 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/Recommend/AbstractResultsPassthrough.php

diff --git a/module/VuFind/src/VuFind/Recommend/AbstractResultsPassthrough.php b/module/VuFind/src/VuFind/Recommend/AbstractResultsPassthrough.php
new file mode 100644
index 00000000000..96ad5c783bd
--- /dev/null
+++ b/module/VuFind/src/VuFind/Recommend/AbstractResultsPassthrough.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Simple abstract recommendation module that simply passes the Results object
+ * through to the template.
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2017.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * @category VuFind
+ * @package  Recommendations
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Chris Hallberg <challber@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
+ */
+namespace VuFind\Recommend;
+
+/**
+ * Simple abstract recommendation module that simply passes the Results object
+ * through to the template.
+ *
+ * @category VuFind
+ * @package  Recommendations
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Chris Hallberg <challber@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
+ */
+class AbstractResultsPassthrough implements RecommendInterface
+{
+    /**
+     * Search results object.
+     *
+     * @var \VuFind\Search\Base\Results
+     */
+    protected $results;
+
+    /**
+     * Store the configuration of the recommendation module.
+     *
+     * @param string $settings Settings from searches.ini.
+     *
+     * @return void
+     */
+    public function setConfig($settings)
+    {
+        // No settings used by default.
+    }
+
+    /**
+     * Called at the end of the Search Params objects' initFromRequest() method.
+     * This method is responsible for setting search parameters needed by the
+     * recommendation module and for reading any existing search parameters that may
+     * be needed.
+     *
+     * @param \VuFind\Search\Base\Params $params  Search parameter object
+     * @param \Zend\StdLib\Parameters    $request Parameter object representing user
+     * request.
+     *
+     * @return void
+     */
+    public function init($params, $request)
+    {
+        // No initialization required by default.
+    }
+
+    /**
+     * Called after the Search Results object has performed its main search.  This
+     * may be used to extract necessary information from the Search Results object
+     * or to perform completely unrelated processing.
+     *
+     * @param \VuFind\Search\Base\Results $results Search results object
+     *
+     * @return void
+     */
+    public function process($results)
+    {
+        $this->results = $results;
+    }
+
+    /**
+     * Get results stored in the object.
+     *
+     * @return \VuFind\Search\Base\Results
+     */
+    public function getResults()
+    {
+        return $this->results;
+    }
+}
diff --git a/module/VuFind/src/VuFind/Recommend/SpellingSuggestions.php b/module/VuFind/src/VuFind/Recommend/SpellingSuggestions.php
index 23675c4f2b3..bd343d2a160 100644
--- a/module/VuFind/src/VuFind/Recommend/SpellingSuggestions.php
+++ b/module/VuFind/src/VuFind/Recommend/SpellingSuggestions.php
@@ -38,64 +38,6 @@ namespace VuFind\Recommend;
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
  */
-class SpellingSuggestions implements RecommendInterface
+class SpellingSuggestions extends AbstractResultsPassthrough
 {
-    /**
-     * Search results object.
-     *
-     * @var \VuFind\Search\Base\Results
-     */
-    protected $results;
-
-    /**
-     * Store the configuration of the recommendation module.
-     *
-     * @param string $settings Settings from searches.ini.
-     *
-     * @return void
-     */
-    public function setConfig($settings)
-    {
-        // No settings used at present.
-    }
-
-    /**
-     * Called at the end of the Search Params objects' initFromRequest() method.
-     * This method is responsible for setting search parameters needed by the
-     * recommendation module and for reading any existing search parameters that may
-     * be needed.
-     *
-     * @param \VuFind\Search\Base\Params $params  Search parameter object
-     * @param \Zend\StdLib\Parameters    $request Parameter object representing user
-     * request.
-     *
-     * @return void
-     */
-    public function init($params, $request)
-    {
-    }
-
-    /**
-     * Called after the Search Results object has performed its main search.  This
-     * may be used to extract necessary information from the Search Results object
-     * or to perform completely unrelated processing.
-     *
-     * @param \VuFind\Search\Base\Results $results Search results object
-     *
-     * @return void
-     */
-    public function process($results)
-    {
-        $this->results = $results;
-    }
-
-    /**
-     * Get results stored in the object.
-     *
-     * @return \VuFind\Search\Base\Results
-     */
-    public function getResults()
-    {
-        return $this->results;
-    }
 }
-- 
GitLab