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