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

Cleaned up some recommendation modules so they do not rely on $this->results...

Cleaned up some recommendation modules so they do not rely on $this->results already being set in the global context -- it is now pulled explicitly from the recommendation object.
parent 41831a09
No related merge requests found
Showing
with 94 additions and 29 deletions
......@@ -100,6 +100,16 @@ class AuthorFacets implements RecommendInterface
$this->results = $results;
}
/**
* Get results stored in the object.
*
* @return \VuFind\Search\Base\Results
*/
public function getResults()
{
return $this->results;
}
/**
* Returns search term.
*
......
......@@ -55,7 +55,8 @@ class AuthorityRecommend implements RecommendInterface
protected $searchObject;
protected $lookfor;
protected $filters = array();
protected $results = array();
protected $results;
protected $recommendations = array();
/**
* setConfig
......@@ -109,6 +110,8 @@ class AuthorityRecommend implements RecommendInterface
*/
public function process($results)
{
$this->results = $results;
// function will return blank on Advanced Search
if ($results->getParams()->getSearchType()== 'advanced') {
return;
......@@ -155,8 +158,8 @@ class AuthorityRecommend implements RecommendInterface
);
// check for duplicates before adding record to recordSet
if (!$this->inArrayR($recordArray['heading'], $this->results)) {
array_push($this->results, $recordArray);
if (!$this->inArrayR($recordArray['heading'], $this->recommendations)) {
array_push($this->recommendations, $recordArray);
} else {
continue;
}
......@@ -164,10 +167,20 @@ class AuthorityRecommend implements RecommendInterface
}
/**
* Get results (for use in the view).
* Get recommendations (for use in the view).
*
* @return array
*/
public function getRecommendations()
{
return $this->recommendations;
}
/**
* Get results stored in the object.
*
* @return \VuFind\Search\Base\Results
*/
public function getResults()
{
return $this->results;
......@@ -183,7 +196,7 @@ class AuthorityRecommend implements RecommendInterface
*
* @return bool
*/
public function inArrayR($needle, $haystack)
protected function inArrayR($needle, $haystack)
{
foreach ($haystack as $v) {
if ($needle == $v) {
......
......@@ -161,4 +161,14 @@ class SideFacets implements RecommendInterface
}
return $result;
}
/**
* Get results stored in the object.
*
* @return \VuFind\Search\Base\Results
*/
public function getResults()
{
return $this->results;
}
}
......@@ -45,6 +45,7 @@ class SwitchType implements RecommendInterface
protected $newHandler; // search handler to try
protected $newHandlerName; // on-screen description of handler
protected $active; // is this module active?
protected $results; // results object
/**
* setConfig
......@@ -94,6 +95,7 @@ class SwitchType implements RecommendInterface
public function process($results)
{
$handler = $results->getParams()->getSearchHandler();
$this->results = $results;
// If the handler is null, we can't figure out a single handler, so this
// is probably an advanced search. In that case, we shouldn't try to change
......@@ -103,6 +105,16 @@ class SwitchType implements RecommendInterface
$this->active = (!is_null($handler) && $handler != $this->newHandler);
}
/**
* Get results stored in the object.
*
* @return \VuFind\Search\Base\Results
*/
public function getResults()
{
return $this->results;
}
/**
* Get the new search handler, or false if it does not apply.
*
......
......@@ -116,6 +116,16 @@ class TopFacets implements RecommendInterface
$this->results = $results;
}
/**
* Get results stored in the object.
*
* @return \VuFind\Search\Base\Results
*/
public function getResults()
{
return $this->results;
}
/**
* Get facet information taken from the search.
*
......
<? if ($this->results->getResultTotal() > 0): ?>
<? if ($this->recommend->getResults()->getResultTotal() > 0): ?>
<? $similarAuthors = $this->recommend->getSimilarAuthors(); ?>
<? if (!empty($similarAuthors['list'])): ?>
<div class="authorbox">
......
<? $data = $this->recommend->getResults(); if (is_array($data) && !empty($data)): ?>
<?
$data = $this->recommend->getRecommendations();
$results = $this->recommend->getResults();
?>
<? if (is_array($data) && !empty($data)): ?>
<div class="authoritybox">
<div><strong><?=$this->transEsc('See also')?>:</strong></div>
<div>
<? for ($i = 0; $i < count($data); $i++): ?>
<?
// Generate a new search URL that replaces the user's current term with the authority term:
$url = $this->url($this->results->getOptions()->getSearchAction())
. $this->results->getUrlQuery()->replaceTerm($this->results->getParams()->getDisplayQuery(), $data[$i]['heading']);
$url = $this->url($results->getOptions()->getSearchAction())
. $results->getUrlQuery()->replaceTerm($results->getParams()->getDisplayQuery(), $data[$i]['heading']);
?>
<a href="<?=$url?>"><?=$this->escapeHtml($data[$i]['heading'])?></a><? if ($i != count($data) - 1): ?>, <? endif; ?>
<? endfor; ?>
......
<? $results = $this->recommend->getResults(); ?>
<div class="sidegroup">
<? $sideFacetSet = $this->recommend->getFacetSet(); ?>
......@@ -22,14 +23,14 @@
<? if (isset($sideFacetSet['tags']) && !empty($sideFacetSet['tags']['list'])): ?>
<div class="sidegroup">
<h4 class="tag"><?=$this->transEsc($sideFacetSet['tags']['label'])?></h4>
<? $filterList = $this->results->getParams()->getFilterList(true);
<? $filterList = $results->getParams()->getFilterList(true);
$tagFilterList = isset($filterList[$sideFacetSet['tags']['label']]) ? $filterList[$sideFacetSet['tags']['label']] : null;
if (!empty($tagFilterList)): ?>
<strong><?=$this->transEsc('Remove Filters')?></strong>
<ul class="filters">
<? $field = $sideFacetSet['tags']['label'];
foreach ($tagFilterList as $filter): ?>
<? $removeLink = $this->currentPath().$this->results->getUrlQuery()->removeFacet($filter['field'], $filter['value']); ?>
<? $removeLink = $this->currentPath().$results->getUrlQuery()->removeFacet($filter['field'], $filter['value']); ?>
<li>
<a href="<?=$removeLink?>"><img src="<?=$this->imageLink('silk/delete.png')?>" alt="<?=$this->transEsc('Delete') ?>"/></a>
<a href="<?=$removeLink?>"><?=$this->transEsc($field)?>: <?=$this->escapeHtml($filter['displayText'])?></a>
......@@ -43,7 +44,7 @@
<? if ($thisFacet['isApplied']): ?>
<?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="<?=$this->transEsc('Selected') ?>"/>
<? else: ?>
<a href="<?=$this->currentPath().$this->results->getUrlQuery()->addFacet('tags', $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>)
<a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet('tags', $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>)
<? endif; ?>
</li>
<? endforeach; ?>
......
<? $results = $this->recommend->getResults(); ?>
<div class="sidegroup">
<? if ($this->results->getResultTotal() > 0): ?><h4><?=$this->transEsc('Narrow Search')?></h4><? endif; ?>
<? $checkboxFilters = $this->results->getParams()->getCheckboxFacets(); if (count($checkboxFilters) > 0): ?>
<? if ($results->getResultTotal() > 0): ?><h4><?=$this->transEsc('Narrow Search')?></h4><? endif; ?>
<? $checkboxFilters = $results->getParams()->getCheckboxFacets(); if (count($checkboxFilters) > 0): ?>
<? foreach ($checkboxFilters as $current): ?>
<div class="checkboxFilter<?=($this->results->getResultTotal() < 1 && !$current['selected'] && !$current['alwaysVisible']) ? ' hide' : ''?>">
<div class="checkboxFilter<?=($results->getResultTotal() < 1 && !$current['selected'] && !$current['alwaysVisible']) ? ' hide' : ''?>">
<input type="checkbox" name="filter[]" value="<?=$this->escapeHtml($current['filter'])?>"
<?=$current['selected'] ? 'checked="checked"' : ''?> id="<?=$this->escapeHtml(str_replace(' ', '', $current['desc']))?>"
onclick="document.location.href='<?=$current['selected'] ? $this->results->getUrlQuery()->removeFilter($current['filter']) : $this->results->getUrlQuery()->addFilter($current['filter'])?>';" />
onclick="document.location.href='<?=$current['selected'] ? $results->getUrlQuery()->removeFilter($current['filter']) : $results->getUrlQuery()->addFilter($current['filter'])?>';" />
<label for="<?=$this->escapeHtml(str_replace(' ', '', $current['desc']))?>"><?=$this->transEsc($current['desc'])?></label>
</div>
<? endforeach; ?>
<? endif; ?>
<? $filterList = $this->results->getParams()->getFilterList(true); if (!empty($filterList)): ?>
<? $filterList = $results->getParams()->getFilterList(true); if (!empty($filterList)): ?>
<strong><?=$this->transEsc('Remove Filters')?></strong>
<ul class="filters">
<? foreach ($filterList as $field => $filters): ?>
<? foreach ($filters as $filter): ?>
<?
$removeLink = $this->currentPath().$this->results->getUrlQuery()->removeFacet($filter['field'], $filter['value']);
$removeLink = $this->currentPath().$results->getUrlQuery()->removeFacet($filter['field'], $filter['value']);
if ($filter['displayText'] == '[* TO *]') $filter['displayText'] = $this->translate('filter_wildcard');
?>
<li>
......@@ -28,12 +29,12 @@
</ul>
<? endif; ?>
<? $sideFacetSet = $this->recommend->getFacetSet(); $dateFacets = $this->recommend->getDateFacets(); ?>
<? if (!empty($sideFacetSet) && $this->results->getResultTotal() > 0): ?>
<? if (!empty($sideFacetSet) && $results->getResultTotal() > 0): ?>
<? foreach ($sideFacetSet as $title => $cluster): ?>
<? if (isset($dateFacets[$title])): ?>
<? /* Load the publication date slider UI widget */ $this->headScript()->appendFile('pubdate_slider.js'); ?>
<form action="" name="<?=$this->escapeHtml($title)?>Filter" id="<?=$this->escapeHtml($title)?>Filter">
<?=$this->results->getUrlQuery()->asHiddenFields(array('filter' => "/^{$title}:.*/"))?>
<?=$results->getUrlQuery()->asHiddenFields(array('filter' => "/^{$title}:.*/"))?>
<input type="hidden" name="daterange[]" value="<?=$this->escapeHtml($title)?>"/>
<fieldset class="publishDateLimit" id="<?=$this->escapeHtml($title)?>">
<legend><?=$this->transEsc($cluster['label'])?></legend>
......@@ -57,7 +58,7 @@
<? if ($thisFacet['isApplied']): ?>
<dd><?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="Selected"/></dd>
<? else: ?>
<dd><a href="<?=$this->currentPath().$this->results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>)</dd>
<dd><a href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$this->escapeHtml($thisFacet['count'])?>)</dd>
<? endif; ?>
<? endforeach; ?>
<? if ($i > 5): ?><dd><a href="#" onclick="lessFacets('<?=$this->escapeHtml($title)?>'); return false;"><?=$this->transEsc('less')?> ...</a></dd><? endif; ?>
......
<? if ($handler = $this->recommend->getNewHandler()): ?>
<div class="info">
<?=$this->transEsc('widen_prefix')?>
<a href="<?=$this->results->getUrlQuery()->setHandler($handler)?>"><?=$this->transEsc($this->recommend->getNewHandlerName())?></a>.
<a href="<?=$this->recommend->getResults()->getUrlQuery()->setHandler($handler)?>"><?=$this->transEsc($this->recommend->getNewHandlerName())?></a>.
</div>
<? endif; ?>
\ No newline at end of file
......@@ -20,7 +20,7 @@
<? if ($thisFacet['isApplied']): ?>
<?=$this->escapeHtml($thisFacet['displayText'])?> <img src="<?=$this->imageLink('silk/tick.png')?>" alt="<?=$this->transEsc('Selected') ?>"/>
<? else: ?>
<a href="<?=$this->currentPath().$this->results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$thisFacet['count'] ?>)
<a href="<?=$this->currentPath().$this->recommend->getResults()->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> (<?=$thisFacet['count'] ?>)
<? endif; ?>
</span>
<? if (count($cluster['list']) > $corner && $iter == count($cluster['list'])): ?>
......
<? $sideFacetSet = $this->recommend->getFacetSet(); ?>
<? if (!empty($sideFacetSet) && $this->results->getResultTotal() > 0): ?>
<?
$results = $this->recommend->getResults();
$sideFacetSet = $this->recommend->getFacetSet();
?>
<? if (!empty($sideFacetSet) && $results->getResultTotal() > 0): ?>
<div data-role="dialog" id="Search-narrow">
<div data-role="header" data-theme="d" data-position="inline">
<h1><?=$this->transEsc('Narrow Search')?></h1>
......@@ -15,7 +18,7 @@
<? if ($thisFacet['isApplied']): ?>
<li data-icon="check" class="checked"><a href="" data-rel="back"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li>
<? else: ?>
<li><a rel="external" href="<?=$this->currentPath().$this->results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li>
<li><a rel="external" href="<?=$this->currentPath().$results->getUrlQuery()->addFacet($title, $thisFacet['value'])?>"><?=$this->escapeHtml($thisFacet['displayText'])?></a> <span class="ui-li-count"><?=$this->escapeHtml($thisFacet['count'])?></span></li>
<? endif; ?>
<? endforeach; ?>
</ul>
......
<? $filterList = $this->results->getParams()->getFilterList(true); if (!empty($filterList)): ?>
<? $results = $this->recommend->getResults(); ?>
<? $filterList = $results->getParams()->getFilterList(true); if (!empty($filterList)): ?>
<ul class="filters" data-role="listview" data-inset="true" data-dividertheme="e">
<li data-role="list-divider"><?=$this->transEsc('adv_search_filters')?></li>
<? $i = 0; foreach ($filterList as $field => $filters): ?>
<? foreach ($filters as $filter): ?>
<?
$removeLink = $this->currentPath().$this->results->getUrlQuery()->removeFacet($filter['field'], $filter['value']);
$removeLink = $this->currentPath().$results->getUrlQuery()->removeFacet($filter['field'], $filter['value']);
if ($filter['displayText'] == '[* TO *]') $filter['displayText'] = $this->translate('filter_wildcard');
?>
<li data-icon="minus">
......
<? if ($handler = $this->recommend->getNewHandler()): ?>
<div class="info">
<?=$this->transEsc('widen_prefix')?>
<a href="<?=$this->results->getUrlQuery()->setHandler($handler)?>"><?=$this->transEsc($this->recommend->getNewHandlerName())?></a>.
<a href="<?=$this->recommend->getResults()->getUrlQuery()->setHandler($handler)?>"><?=$this->transEsc($this->recommend->getNewHandlerName())?></a>.
</div>
<? endif; ?>
\ 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