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

Added SummonBestBetsDeferred and SummonDatabasesDeferred modules.

- Refactored SummonResultsDeferred to share functionality.
- Resolves VUFIND-956.
parent c210d82b
Branches
Tags
No related merge requests found
Showing
with 322 additions and 75 deletions
......@@ -207,12 +207,16 @@ CallNumber = callnumber
; Summon search, the [GET parameter] setting will be ignored and the actual
; current Summon search will be used instead. The parameter only needs to be
; specified when combining this module with a non-Summon-based search module.
; SummonBestBetsDeferred:[GET parameter]
; Same as SummonBestBets, but loaded via AJAX.
; SummonDatabases:[GET parameter]
; Display Summon-generated database recommendations matching the terms found
; in the specified GET parameter. NOTE: If you are using this module with a
; Summon search, the [GET parameter] setting will be ignored and the actual
; current Summon search will be used instead. The parameter only needs to be
; specified when combining this module with a non-Summon-based search module.
; SummonDatabasesDeferred:[GET parameter]
; Same as SummonDatabases, but loaded via AJAX.
; SummonResults:[GET parameter]:[result limit]
; Display Summon search results matching the terms found in the specified
; GET parameter (default = "lookfor"), limited to a specified number of
......
......@@ -332,6 +332,8 @@ $config = array(
'openlibrarysubjectsdeferred' => 'VuFind\Recommend\OpenLibrarySubjectsDeferred',
'pubdatevisajax' => 'VuFind\Recommend\PubDateVisAjax',
'resultgooglemapajax' => 'VuFind\Recommend\ResultGoogleMapAjax',
'summonbestbetsdeferred' => 'VuFind\Recommend\SummonBestBetsDeferred',
'summondatabasesdeferred' => 'VuFind\Recommend\SummonDatabasesDeferred',
'summonresultsdeferred' => 'VuFind\Recommend\SummonResultsDeferred',
'switchtype' => 'VuFind\Recommend\SwitchType',
),
......
<?php
/**
* Abstract base for deferred-load Summon recommendations modules
*
* PHP version 5
*
* Copyright (C) Villanova University 2014.
*
* 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;
/**
* Abstract base for deferred-load Summon recommendations modules
*
* @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 AbstractSummonRecommendDeferred 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;
/**
* Name of module being loaded by AJAX -- MUST be set in constructor!
*
* @var string
*/
protected $module = null;
/**
* Number of expected module parameters (from .ini config)
*
* @var int
*/
protected $paramCount = 1;
/**
* 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
* @throws \Exception
*/
public function init($params, $request)
{
// Validate module setting:
if (null === $this->module) {
throw new \Exception('Missing module property');
}
// 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 < $this->paramCount; $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=' . urlencode($this->module)
. '&params=' . urlencode($this->processedParams)
. '&lookfor=' . urlencode($this->lookfor);
}
}
\ No newline at end of file
<?php
/**
* SummonBestBetsDeferred 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;
/**
* SummonBestBetsDeferred Recommendations Module
*
* This class sets up an AJAX call to trigger a call to the SummonBestBets
* 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 SummonBestBetsDeferred extends AbstractSummonRecommendDeferred
{
/**
* Constructor
*/
public function __construct()
{
$this->module = 'SummonBestBets';
}
}
\ No newline at end of file
<?php
/**
* SummonDatabasesDeferred 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;
/**
* SummonDatabasesDeferred Recommendations Module
*
* This class sets up an AJAX call to trigger a call to the SummonDatabases
* 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 SummonDatabasesDeferred extends AbstractSummonRecommendDeferred
{
/**
* Constructor
*/
public function __construct()
{
$this->module = 'SummonDatabases';
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ namespace VuFind\Recommend;
* SummonResultsDeferred Recommendations Module
*
* This class sets up an AJAX call to trigger a call to the SummonResults
* module.
* module.
*
* @category VuFind2
* @package Recommendations
......@@ -40,22 +40,8 @@ namespace VuFind\Recommend;
* @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
class SummonResultsDeferred extends AbstractSummonRecommendDeferred
{
/**
* Raw configuration parameters
*
* @var string
*/
protected $rawParams;
/**
* Current search query
*
* @var string
*/
protected $lookfor;
/**
* Label for current search type
*
......@@ -64,24 +50,12 @@ class SummonResultsDeferred implements RecommendInterface
protected $typeLabel = '';
/**
* 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
* Constructor
*/
public function setConfig($settings)
public function __construct()
{
$this->rawParams = $settings;
$this->module = 'SummonResults';
$this->paramCount = 2;
}
/**
......@@ -100,23 +74,7 @@ class SummonResultsDeferred implements RecommendInterface
*/
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);
parent::init($params, $request);
// Collect the label for the current search type:
if (is_object($params)) {
......@@ -124,29 +82,6 @@ class SummonResultsDeferred implements RecommendInterface
$params->getSearchHandler()
);
}
// 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
}
/**
......@@ -156,8 +91,6 @@ class SummonResultsDeferred implements RecommendInterface
*/
public function getUrlParams()
{
return 'mod=SummonResults&params=' . urlencode($this->processedParams)
. '&lookfor=' . urlencode($this->lookfor)
. '&typeLabel=' . urlencode($this->typeLabel);
return parent::getUrlParams() . '&typeLabel=' . urlencode($this->typeLabel);
}
}
\ No newline at end of file
<?
// Set up Javascript for use below:
$loadJs = 'var url = path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#SummonDeferredBestBets').load(url);";
?>
<div id="SummonDeferredBestBets">
<p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
</div>
\ No newline at end of file
<?
// Set up Javascript for use below:
$loadJs = 'var url = path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#SummonDeferredDatabases').load(url);";
?>
<div id="SummonDeferredDatabases">
<p><?=$this->transEsc("Loading")?>... <img src="<?=$this->imageLink('ajax_loading.gif')?>" /></p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
</div>
\ No newline at end of file
<?
// Set up Javascript for use below:
$loadJs = 'var url = path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#SummonDeferredBestBets').load(url);";
?>
<div id="SummonDeferredBestBets">
<p><?=$this->transEsc("Loading")?>... <i class="icon-spinner"></i></p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
</div>
\ No newline at end of file
<?
// Set up Javascript for use below:
$loadJs = 'var url = path + "/AJAX/Recommend?' . $this->recommend->getUrlParams() . '";'
. "\$('#SummonDeferredDatabases').load(url);";
?>
<div id="SummonDeferredDatabases">
<p><?=$this->transEsc("Loading")?>... <i class="icon-spinner"></i></p>
<?=$this->inlineScript(\Zend\View\Helper\HeadScript::SCRIPT, $loadJs, 'SET')?>
</div>
\ No newline at end of file
<? /* Not supported in mobile theme. */ ?>
\ 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