From e50f2f795e7633d05c1c3133650197ae198e84cd Mon Sep 17 00:00:00 2001 From: Anna Headley <anna3LC@gmail.com> Date: Wed, 25 Mar 2015 11:48:51 -0400 Subject: [PATCH] new recommendation module to provide a link to the alphabrowse index --- config/vufind/searches.ini | 3 + languages/en.ini | 1 + module/VuFind/config/module.config.php | 1 + .../src/VuFind/Recommend/AlphaBrowseLink.php | 120 ++++++++++++++++++ .../templates/Recommend/AlphaBrowseLink.phtml | 14 ++ .../templates/Recommend/AlphaBrowseLink.phtml | 14 ++ .../templates/Recommend/AlphaBrowseLink.phtml | 14 ++ 7 files changed, 167 insertions(+) create mode 100644 module/VuFind/src/VuFind/Recommend/AlphaBrowseLink.php create mode 100644 themes/blueprint/templates/Recommend/AlphaBrowseLink.phtml create mode 100644 themes/bootstrap3/templates/Recommend/AlphaBrowseLink.phtml create mode 100644 themes/jquerymobile/templates/Recommend/AlphaBrowseLink.phtml diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index 8c037ef2816..9c0922189e3 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -335,6 +335,8 @@ CallNumber = callnumber-sort ; ; Available modules recommended for use in the "no results" area: ; +; AlphaBrowseLink:index +; Use the query to generate a link to the specified alphabrowse index ; SwitchQuery:[backend]:[checks to skip]:[transforms to add] ; This module analyzes the user's query and offers suggestions for ways to ; improve it. [backend] is the name of the search backend currently in use, @@ -367,6 +369,7 @@ CallNumber[] = "TopFacets:ResultsTop" ; disable spelling in this conte [NoResultsRecommendations] CallNumber[] = SwitchQuery::wildcard:truncatechar +;CallNumber[] = AlphaBrowseLink:lcc ; These settings control the top and side recommendations within the special Author ; module (the page accessed by clicking on an author's name within the search diff --git a/languages/en.ini b/languages/en.ini index 370cb8dbb62..408c6fcb855 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -49,6 +49,7 @@ All Fields = "All Fields" All Pages Loaded = "All Pages Loaded" All Text = "All Text" alphabrowse_matches = "Results" +alphabrowselink_html = "Browse entries by %%index%% starting from <a href="%%url%%">%%from%%</a>." An error has occurred = "An error has occurred" An error occurred during execution; please try again later. = "An error occurred during execution; please try again later." AND = "AND" diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 82c54e74b96..f623d9eaca4 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -419,6 +419,7 @@ $config = [ 'worldcatterms' => 'VuFind\Recommend\Factory::getWorldCatTerms', ], 'invokables' => [ + 'alphabrowselink' => 'VuFind\Recommend\AlphaBrowseLink', 'europeanaresultsdeferred' => 'VuFind\Recommend\EuropeanaResultsDeferred', 'facetcloud' => 'VuFind\Recommend\FacetCloud', 'openlibrarysubjects' => 'VuFind\Recommend\OpenLibrarySubjects', diff --git a/module/VuFind/src/VuFind/Recommend/AlphaBrowseLink.php b/module/VuFind/src/VuFind/Recommend/AlphaBrowseLink.php new file mode 100644 index 00000000000..246e76e3045 --- /dev/null +++ b/module/VuFind/src/VuFind/Recommend/AlphaBrowseLink.php @@ -0,0 +1,120 @@ +<?php +/** + * AlphaBrowseLink Recommendations Module + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Recommendations + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki + */ +namespace VuFind\Recommend; + +/** + * AlphaBrowseLink Recommendations Module + * + * This class recommends a look at the alphabrowse index. + * + * @category VuFind2 + * @package Recommendations + * @author Demian Katz <demian.katz@villanova.edu> + * @author Anna Headley <aheadle1@swarthmore.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki + */ +class AlphaBrowseLink implements RecommendInterface +{ + /** + * Search query submitted + * + * @var string + */ + protected $query; + + /** + * Alphabrowse index to link to + * + * @var string + */ + protected $index; + + /** + * Store the configuration of the recommendation module. + * + * @param string $settings Settings from searches.ini. + * + * @return void + */ + public function setConfig($settings) + { + // so far there's just the one setting. + $this->index = $settings; + } + + /** + * 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->query = $results->getParams()->getDisplayQuery(); + } + + /** + * Get the search query. + * + * @return string + */ + public function getQuery() + { + return $this->query; + } + + /** + * Get the alphabrowse index to link to + * + * @return string + */ + public function getIndex() + { + return $this->index; + } +} diff --git a/themes/blueprint/templates/Recommend/AlphaBrowseLink.phtml b/themes/blueprint/templates/Recommend/AlphaBrowseLink.phtml new file mode 100644 index 00000000000..ff7aa235d05 --- /dev/null +++ b/themes/blueprint/templates/Recommend/AlphaBrowseLink.phtml @@ -0,0 +1,14 @@ +<? + $index = $this->recommend->getIndex(); + $from = $this->recommend->getQuery(); + $link = $this->translate( + 'alphabrowselink_html', + [ + '%%index%%' => $this->transEsc('browse_' . $index), + '%%from%%' => $this->escapeHtml($from), + '%%url%%' => $this->url('alphabrowse-home') + . '?from=' . urlencode($from) . '&source=' . urlencode($index) + ] + ); +?> +<div class="info"><?=$link?></div> \ No newline at end of file diff --git a/themes/bootstrap3/templates/Recommend/AlphaBrowseLink.phtml b/themes/bootstrap3/templates/Recommend/AlphaBrowseLink.phtml new file mode 100644 index 00000000000..632a7f412d0 --- /dev/null +++ b/themes/bootstrap3/templates/Recommend/AlphaBrowseLink.phtml @@ -0,0 +1,14 @@ +<? + $index = $this->recommend->getIndex(); + $from = $this->recommend->getQuery(); + $link = $this->translate( + 'alphabrowselink_html', + [ + '%%index%%' => $this->transEsc('browse_' . $index), + '%%from%%' => $this->escapeHtml($from), + '%%url%%' => $this->url('alphabrowse-home') + . '?from=' . urlencode($from) . '&source=' . urlencode($index) + ] + ); +?> +<div class="alert alert-info"><?=$link?></div> \ No newline at end of file diff --git a/themes/jquerymobile/templates/Recommend/AlphaBrowseLink.phtml b/themes/jquerymobile/templates/Recommend/AlphaBrowseLink.phtml new file mode 100644 index 00000000000..ff7aa235d05 --- /dev/null +++ b/themes/jquerymobile/templates/Recommend/AlphaBrowseLink.phtml @@ -0,0 +1,14 @@ +<? + $index = $this->recommend->getIndex(); + $from = $this->recommend->getQuery(); + $link = $this->translate( + 'alphabrowselink_html', + [ + '%%index%%' => $this->transEsc('browse_' . $index), + '%%from%%' => $this->escapeHtml($from), + '%%url%%' => $this->url('alphabrowse-home') + . '?from=' . urlencode($from) . '&source=' . urlencode($index) + ] + ); +?> +<div class="info"><?=$link?></div> \ No newline at end of file -- GitLab