Skip to content
Snippets Groups Projects
Commit 144683e3 authored by Demian Katz's avatar Demian Katz
Browse files

New recommendation module: SummonResultsDeferred.

Resolves VUFIND-838.
parent 529c465f
No related merge requests found
...@@ -211,6 +211,8 @@ CallNumber = callnumber ...@@ -211,6 +211,8 @@ CallNumber = callnumber
; Display Summon search results matching the terms found in the specified ; Display Summon search results matching the terms found in the specified
; GET parameter (default = "lookfor"), limited to a specified number of ; GET parameter (default = "lookfor"), limited to a specified number of
; matches (default = 5). ; matches (default = 5).
; SummonResultsDeferred:[GET parameter]:[result limit]
; Same as SummonResults, but loaded via AJAX.
; WebResults:[GET parameter]:[result limit] ; WebResults:[GET parameter]:[result limit]
; Display website search results matching the terms found in the specified ; Display website search results matching the terms found in the specified
; GET parameter (default = "lookfor"), limited to a specified number of ; GET parameter (default = "lookfor"), limited to a specified number of
......
...@@ -636,6 +636,7 @@ $config = array( ...@@ -636,6 +636,7 @@ $config = array(
'openlibrarysubjectsdeferred' => 'VuFind\Recommend\OpenLibrarySubjectsDeferred', 'openlibrarysubjectsdeferred' => 'VuFind\Recommend\OpenLibrarySubjectsDeferred',
'pubdatevisajax' => 'VuFind\Recommend\PubDateVisAjax', 'pubdatevisajax' => 'VuFind\Recommend\PubDateVisAjax',
'resultgooglemapajax' => 'VuFind\Recommend\ResultGoogleMapAjax', 'resultgooglemapajax' => 'VuFind\Recommend\ResultGoogleMapAjax',
'summonresultsdeferred' => 'VuFind\Recommend\SummonResultsDeferred',
'switchtype' => 'VuFind\Recommend\SwitchType', 'switchtype' => 'VuFind\Recommend\SwitchType',
), ),
), ),
......
<?php
/**
* SummonResultsDeferred 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 Lutz Biedinger <lutz.biedinger@gmail.com>
* @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;
/**
* SummonResultsDeferred Recommendations Module
*
* This class sets up an AJAX call to trigger a call to the SummonResults
* module.
*
* @category VuFind2
* @package Recommendations
* @author Lutz Biedinger <lutz.biedigner@gmail.com>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:recommendation_modules Wiki
*/
class SummonResultsDeferred 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;
/**
* setConfig
*
* Store the configuration of the recommendation module.
*
* @param string $settings Settings from searches.ini.
*
* @return void
*/
public function setConfig($settings)
{
$this->rawParams = $settings;
}
/**
* init
*
* 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)
{
// 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] = isset($settings[$i]) ? $settings[$i] : '';
}
// Collect the best possible search term(s):
$lookforParam = empty($settings[0]) ? 'lookfor' : $settings[0];
$this->lookfor = $request->get($lookforParam, '');
if (empty($this->lookfor) && is_object($params)) {
$this->lookfor = $params->getQuery()->getAllTerms();
}
$this->lookfor = trim($this->lookfor);
// In AJAX mode, the query will always be found in the 'lookfor' parameter,
// so override the setting:
$settings[0] = 'lookfor';
// Now rebuild the parameters to pass via AJAX:
$this->processedParams = implode(':', $settings);
}
/**
* process
*
* 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=SummonResults&params=' . urlencode($this->processedParams)
. '&lookfor=' . urlencode($this->lookfor);
}
}
\ No newline at end of file
<?
// Set up Javascript for use below:
$loadJs = 'var url = path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#SummonDeferredRecommend').load(url);";
?>
<div id="SummonDeferredRecommend">
<p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs)?>
</div>
\ No newline at end of file
<? /* Not supported in mobile theme. */ ?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment