diff --git a/config/vufind/searches.ini b/config/vufind/searches.ini index 5efa7845082eb01db5a305ebbbb497b6a71e50ab..b8839083a4d6d9369689e5d04b74b0b3e817979c 100644 --- a/config/vufind/searches.ini +++ b/config/vufind/searches.ini @@ -209,6 +209,12 @@ CallNumber = callnumber-sort ; DPLATerms:[collapsed] ; Display results from the DPLA catalog. Provide a boolean to have the sidebar ; collapsed or open on page load. +; EDSResults:[GET parameter]:[result limit] +; Display EDS search results matching the terms found in the specified +; GET parameter (default = "lookfor"), limited to a specified number of +; matches (default = 5). +; EDSResultsDeferred:[GET parameter]:[result limit] +; Same as EDSResults, but loaded via AJAX. ; EuropeanaResults:[url]:[requestParam]:[limit]:[unwanted data providers] ; Display search results from Europeana.eu API. ; Parameters (all are optional): diff --git a/languages/en.ini b/languages/en.ini index 7bd03830f6788b259050880f9738b981fca561a8..8167589548b8da48a559397539de153b6cf63c9d 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -322,6 +322,7 @@ edit_list = "Edit List" edit_list_fail = "Sorry, you are not permitted to edit this list" edit_list_success = "List successfully updated." Edition = "Edition" +EDS Results = "EDS Results" eds_expander_fulltext = "Also search within the full text of the articles" eds_expander_relatedsubjects = "Apply equivalent subjects" eds_expander_thesaurus = "Apply related words" @@ -674,6 +675,7 @@ mobile_link = "You appear to be on a mobile device; switch to mobile view?" Monograph Title = "Monograph Title" more = "more" More catalog results = "More catalog results" +More EDS Results = "More EDS Results" More options = "More options" More Summon results = "More Summon results" More Topics = "More Topics" diff --git a/module/VuFind/src/VuFind/Recommend/EDSResults.php b/module/VuFind/src/VuFind/Recommend/EDSResults.php new file mode 100644 index 0000000000000000000000000000000000000000..7341ca7c9fcd49c3fe43ddb8d60b836640a06331 --- /dev/null +++ b/module/VuFind/src/VuFind/Recommend/EDSResults.php @@ -0,0 +1,52 @@ +<?php +/** + * EDSResults Recommendations Module + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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> + * @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; + +/** + * EDSResults Recommendations Module + * + * This class provides recommendations by doing a search of EDS. + * + * @category VuFind + * @package Recommendations + * @author Demian Katz <demian.katz@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 EDSResults extends SearchObject +{ + /** + * Get the search class ID to use for building search objects. + * + * @return string + */ + protected function getSearchClassId() + { + return 'EDS'; + } +} diff --git a/module/VuFind/src/VuFind/Recommend/EDSResultsDeferred.php b/module/VuFind/src/VuFind/Recommend/EDSResultsDeferred.php new file mode 100644 index 0000000000000000000000000000000000000000..a47b74abb0a907a3da79b3d508cf3a7e5f68e368 --- /dev/null +++ b/module/VuFind/src/VuFind/Recommend/EDSResultsDeferred.php @@ -0,0 +1,131 @@ +<?php +/** + * EDSResultsDeferred Recommendations Module + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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> + * @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; + +/** + * EDSResultsDeferred Recommendations Module + * + * This class sets up an AJAX call to trigger a call to the EDSResults module. + * + * @category VuFind + * @package Recommendations + * @author Demian Katz <demian.katz@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 EDSResultsDeferred implements RecommendInterface +{ + /** + * Raw configuration parameters + * + * @var string + */ + protected $rawParams; + + /** + * Current search query + * + * @var string + */ + protected $lookfor; + + /** + * Configuration parameters processed for submission via AJAX + * + * @var string + */ + protected $processedParams; + + /** + * Store the configuration of the recommendation module. + * + * @param string $settings Settings from searches.ini. + * + * @return void + */ + public function setConfig($settings) + { + $this->rawParams = $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 \Laminas\Stdlib\Parameters $request Parameter object representing user + * request. + * + * @return void + */ + public function init($params, $request) + { + // Parse out parameters: + $settings = explode(':', $this->rawParams); + + // Make sure all elements of the params array are filled in, even if just + // with a blank string, so we can rebuild the parameters to pass through + // AJAX later on! + for ($i = 0; $i < 2; $i++) { + $settings[$i] = $settings[$i] ?? ''; + } + + // Map the user-specified query field to 'lookfor' for simplicity: + $this->lookfor + = $request->get(empty($settings[0]) ? 'lookfor' : $settings[0], ''); + $settings[0] = 'lookfor'; + $this->processedParams = implode(':', $settings); + } + + /** + * 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) + { + // No action needed + } + + /** + * Get the URL parameters needed to make the AJAX recommendation request. + * + * @return string + */ + public function getUrlParams() + { + return 'mod=EDSResults¶ms=' . urlencode($this->processedParams) + . '&lookfor=' . urlencode($this->lookfor); + } +} diff --git a/module/VuFind/src/VuFind/Recommend/PluginManager.php b/module/VuFind/src/VuFind/Recommend/PluginManager.php index 3c3762fd5ba17f26cd875695597be60161b87583..9a80cf2b5a07983640260172687292137e9eb41b 100644 --- a/module/VuFind/src/VuFind/Recommend/PluginManager.php +++ b/module/VuFind/src/VuFind/Recommend/PluginManager.php @@ -55,6 +55,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager 'collectionsidefacets' => CollectionSideFacets::class, 'doi' => DOI::class, 'dplaterms' => DPLATerms::class, + 'edsresults' => EDSResults::class, + 'edsresultsdeferred' => EDSResultsDeferred::class, 'europeanaresults' => EuropeanaResults::class, 'europeanaresultsdeferred' => EuropeanaResultsDeferred::class, 'expandfacets' => ExpandFacets::class, @@ -105,6 +107,8 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager Deprecated::class => InvokableFactory::class, DOI::class => InvokableFactory::class, DPLATerms::class => DPLATermsFactory::class, + EDSResults::class => InjectSearchRunnerFactory::class, + EDSResultsDeferred::class => InvokableFactory::class, EuropeanaResults::class => EuropeanaResultsFactory::class, EuropeanaResultsDeferred::class => InvokableFactory::class, ExpandFacets::class => ExpandFacetsFactory::class, diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EDSResultsDeferredTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EDSResultsDeferredTest.php new file mode 100644 index 0000000000000000000000000000000000000000..47988ff5cd68bfbde5e0d52e7c15b8e918144f14 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EDSResultsDeferredTest.php @@ -0,0 +1,57 @@ +<?php +/** + * EDSResultsDeferred recommendation module Test Class + * + * PHP version 7 + * + * Copyright (C) Villanova University 2020. + * + * 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 Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +namespace VuFindTest\Recommend; + +/** + * EDSResultsDeferred recommendation module Test Class + * + * @category VuFind + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +class EDSResultsDeferredTest extends \VuFindTest\Unit\RecommendDeferredTestCase +{ + /** + * Test standard operation + * + * @return void + */ + public function testStandardOperation() + { + $mod = $this->getRecommend( + 'VuFind\Recommend\EDSResultsDeferred', ':3', + new \Laminas\Stdlib\Parameters(['lookfor' => 'foo']) + ); + $this->assertEquals( + 'mod=EDSResults¶ms=lookfor%3A3&lookfor=foo', + $mod->getUrlParams() + ); + } +} diff --git a/themes/bootstrap3/templates/Recommend/EDSResults.phtml b/themes/bootstrap3/templates/Recommend/EDSResults.phtml new file mode 100644 index 0000000000000000000000000000000000000000..69579de96147822821c43d398d9903db199b060b --- /dev/null +++ b/themes/bootstrap3/templates/Recommend/EDSResults.phtml @@ -0,0 +1,22 @@ +<?php $searchObject = $this->recommend->getResults(); $results = $searchObject->getResults(); if (!empty($results)): ?> + <h4><?=$this->transEsc('EDS Results')?></h4> + <div class="list-group"> + <?php foreach ($results as $driver): ?> + <div class="list-group-item"> + <span> + <?php $formats = $driver->getFormats(); $format = $formats[0] ?? ''; ?> + <a href="<?=$this->recordLink()->getUrl($driver)?>" class="title <?=$this->record($driver)->getFormatClass($format)?>"> + <?=$this->record($driver)->getTitleHtml()?> + </a> + <?php $summAuthors = $driver->getPrimaryAuthorsWithHighlighting(); if (!empty($summAuthors)): ?> + <span class="small"> + <?=$this->transEsc('by')?> + <a href="<?=$this->record($driver)->getLink('author', $this->highlight($summAuthors[0], null, true, false))?>"><?=$this->highlight($summAuthors[0])?></a><?php if (count($summAuthors) > 1): ?>, <?=$this->transEsc('more_authors_abbrev')?><?php endif; ?> + </span> + <?php endif; ?> + </span> + </div> + <?php endforeach; ?> + <a class="list-group-item" href="<?=$this->url($searchObject->getOptions()->getSearchAction()) . $searchObject->getUrlQuery()->setLimit($searchObject->getOptions()->getDefaultLimit())?>"><?=$this->transEsc('More EDS results')?>...</a> + </div> +<?php endif ?> diff --git a/themes/bootstrap3/templates/Recommend/EDSResultsDeferred.phtml b/themes/bootstrap3/templates/Recommend/EDSResultsDeferred.phtml new file mode 100644 index 0000000000000000000000000000000000000000..4a369ac6e59bf1ecdf5398264bb6429c2fa7c078 --- /dev/null +++ b/themes/bootstrap3/templates/Recommend/EDSResultsDeferred.phtml @@ -0,0 +1,9 @@ +<?php + // Set up Javascript for use below: + $loadJs = 'var url = VuFind.path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";' + . "\$('#edsResultsDeferredRecommend').load(url);"; +?> +<div id="edsResultsDeferredRecommend"> + <p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p> + <?=$this->inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?> +</div>