Skip to content
Snippets Groups Projects
Commit 98109a4d authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Fixed interaction between hidden tab filters and advanced search.

- Also added id to tab details array to enable additional customizations.
parent 4288568a
No related merge requests found
......@@ -28,7 +28,8 @@
* @link http://vufind.org/wiki/vufind2:developer_manual Wiki
*/
namespace VuFind\View\Helper\Root;
use VuFind\Search\Results\PluginManager,
use VuFind\Search\Base\Results,
VuFind\Search\Results\PluginManager,
VuFind\Search\SearchTabsHelper,
Zend\View\Helper\Url,
Zend\Http\Request;
......@@ -112,7 +113,7 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
&& $this->helper->filtersMatch($class, $hiddenFilters, $filters)
) {
$matchFound = true;
$retVal[] = $this->createSelectedTab($class, $label);
$retVal[] = $this->createSelectedTab($key, $class, $label);
} else if ($type == 'basic') {
if (!isset($activeOptions)) {
$activeOptions
......@@ -121,11 +122,11 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
$newUrl = $this->remapBasicSearch(
$activeOptions, $class, $query, $handler, $filters
);
$retVal[] = $this->createBasicTab($class, $label, $newUrl);
$retVal[] = $this->createBasicTab($key, $class, $label, $newUrl);
} else if ($type == 'advanced') {
$retVal[] = $this->createAdvancedTab($class, $label, $filters);
$retVal[] = $this->createAdvancedTab($key, $class, $label, $filters);
} else {
$retVal[] = $this->createHomeTab($class, $label, $filters);
$retVal[] = $this->createHomeTab($key, $class, $label, $filters);
}
}
if (!$matchFound && !empty($retVal)) {
......@@ -159,14 +160,16 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
/**
* Create information representing a selected tab.
*
* @param string $id Tab ID
* @param string $class Search class ID
* @param string $label Display text for tab
*
* @return array
*/
protected function createSelectedTab($class, $label)
protected function createSelectedTab($id, $class, $label)
{
return [
'id' => $id,
'class' => $class,
'label' => $label,
'selected' => true
......@@ -209,15 +212,17 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
/**
* Create information representing a basic search tab.
*
* @param string $id Tab ID
* @param string $class Search class ID
* @param string $label Display text for tab
* @param string $newUrl Target search URL
*
* @return array
*/
protected function createBasicTab($class, $label, $newUrl)
protected function createBasicTab($id, $class, $label, $newUrl)
{
return [
'id' => $id,
'class' => $class,
'label' => $label,
'selected' => false,
......@@ -228,27 +233,23 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
/**
* Create information representing a tab linking to "search home."
*
* @param string $id Tab ID
* @param string $class Search class ID
* @param string $label Display text for tab
* @param array $filters Tab filters
*
* @return array
*/
protected function createHomeTab($class, $label, $filters)
protected function createHomeTab($id, $class, $label, $filters)
{
// Set up results object for URL building:
$results = $this->results->get($class);
$params = $results->getParams();
foreach ($filters as $filter) {
$params->addHiddenFilter($filter);
}
// If an advanced search is available, link there; otherwise, just go
// to the search home:
$results = $this->results->get($class);
$urlParams = $results->getUrlQuery()->getParams(false);
$url = $this->url->__invoke($results->getOptions()->getSearchHomeAction())
. ($urlParams !== '?' ? $urlParams : '');
. $this->buildUrlHiddenFilters($results, $filters);
return [
'id' => $id,
'class' => $class,
'label' => $label,
'selected' => false,
......@@ -259,20 +260,25 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
/**
* Create information representing an advanced search tab.
*
* @param string $class Search class ID
* @param string $label Display text for tab
* @param string $id Tab ID
* @param string $class Search class ID
* @param string $label Display text for tab
* @param array $filters Tab filters
*
* @return array
*/
protected function createAdvancedTab($class, $label)
protected function createAdvancedTab($id, $class, $label, $filters)
{
// If an advanced search is available, link there; otherwise, just go
// to the search home:
$options = $this->results->get($class)->getOptions();
$results = $this->results->get($class);
$options = $results->getOptions();
$advSearch = $options->getAdvancedSearchAction();
$url = $this->url
->__invoke($advSearch ? $advSearch : $options->getSearchHomeAction());
->__invoke($advSearch ? $advSearch : $options->getSearchHomeAction())
. $this->buildUrlHiddenFilters($results, $filters);
return [
'id' => $id,
'class' => $class,
'label' => $label,
'selected' => false,
......@@ -280,4 +286,22 @@ class SearchTabs extends \Zend\View\Helper\AbstractHelper
];
}
/**
* Build a hidden filter query fragment from the given filters
*
* @param Results $results Search results
* @param array $filters Filters
*
* @return string Query parameters
*/
protected function buildUrlHiddenFilters(Results $results, $filters)
{
// Set up results object for URL building:
$params = $results->getParams();
foreach ($filters as $filter) {
$params->addHiddenFilter($filter);
}
$urlParams = $results->getUrlQuery()->getParams(false);
return $urlParams !== '?' ? $urlParams : '';
}
}
......@@ -23,8 +23,10 @@
}
$hasDefaultsApplied = $this->saved->getParams()->hasDefaultsApplied();
$searchFilters = $this->saved->getParams()->getFilterList();
$hiddenFilters = $this->saved->getParams()->getHiddenFilters();
} else {
$hasDefaultsApplied = $searchDetails = $searchFilters = $groups = false;
$hiddenFilters = $this->searchtabs()->getHiddenFilters($this->searchClassId, true);
}
// Step 1: Load the javascript
......@@ -62,6 +64,11 @@
<?=$this->flashmessages()?>
<div role="search">
<form name="searchForm" id="advSearchForm" method="get" action="<?=$this->url($this->options->getSearchAction())?>">
<? foreach ($hiddenFilters as $key => $filter): ?>
<? foreach ($filter as $value): ?>
<input type="hidden" name="hiddenFilters[]" value="<?=$this->escapeHtmlAttr($key) . ':' . $this->escapeHtmlAttr($value)?>" />
<? endforeach; ?>
<? endforeach; ?>
<div class="row">
<div class="<?=$this->layoutClass('mainbody')?>">
<input type="hidden" name="sort" value="relevance">
......
......@@ -12,6 +12,7 @@
);
$handlerCount = count($handlers);
$basicSearch = $this->searchbox()->combinedHandlersActive() ? 'combined-searchbox' : $options->getSearchAction();
$searchHome = $options->getSearchHomeAction();
$advSearch = $options->getAdvancedSearchAction();
$lastSort = $options->getLastSort();
$lastLimit = $options->getLastLimit();
......@@ -48,7 +49,16 @@
<? endif; ?>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> <?=$this->transEsc("Find")?></button>
<? if ($advSearch): ?>
<a href="<?=$this->url($advSearch) . ((isset($this->searchId) && $this->searchId) ? '?edit=' . $this->escapeHtmlAttr($this->searchId) : '') ?>" class="btn btn-link" rel="nofollow"><?=$this->transEsc("Advanced")?></a>
<?
$hiddenFilterParams = [];
foreach ($hiddenFilters as $key => $filter) {
foreach ($filter as $value) {
$hiddenFilterParams[] = urlencode('hiddenFilters[]') . '=' . urlencode("$key:$value");
}
}
$hiddenFilterParams = empty($hiddenFilterParams) ? '' : '?' . implode('&', $hiddenFilterParams);
?>
<a href="<?=$this->url($advSearch) . ((isset($this->searchId) && $this->searchId) ? '?edit=' . $this->escapeHtmlAttr($this->searchId) : $hiddenFilterParams) ?>" class="btn btn-link" rel="nofollow"><?=$this->transEsc("Advanced")?></a>
<? endif; ?>
<? $shards = $options->getShards(); if ($options->showShardCheckboxes() && !empty($shards)): ?>
......
......@@ -12,6 +12,11 @@
$searchHome['action'] = 'Home';
$lastSort = $options->getLastSort();
$lastLimit = $options->getLastLimit();
if (isset($this->saved) && is_object($this->saved)) {
$hiddenFilters = $this->saved->getParams()->getHiddenFilters();
} else {
$hiddenFilters = $this->searchtabs()->getHiddenFilters($this->searchClassId, true);
}
?>
<div data-role="page" id="Search-home">
<?=$this->mobileMenu()->header(array('hideSearchLink' => true))?>
......@@ -56,6 +61,11 @@
echo '<input type="hidden" name="sort" value="' . $this->escapeHtmlAttr($lastSort) . '" />';
}
?>
<? foreach ($hiddenFilters as $key => $filter): ?>
<? foreach ($filter as $value): ?>
<input type="hidden" name="hiddenFilters[]" value="<?=$this->escapeHtmlAttr($key) . ':' . $this->escapeHtmlAttr($value)?>" />
<? endforeach; ?>
<? endforeach; ?>
</form>
</div>
<?=$this->mobileMenu()->footer()?>
......
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