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

Refactored "retain filter" behavior to view helper.

parent a7d9dda6
No related merge requests found
<?php
/**
* Search box view helper
*
* 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 View_Helpers
* @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:developer_manual Wiki
*/
namespace VuFind\View\Helper\Root;
/**
* Search box view helper
*
* @category VuFind2
* @package View_Helpers
* @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:developer_manual Wiki
*/
class SearchBox extends \Zend\View\Helper\AbstractHelper
{
/**
* Get an array of filter information for use by the "retain filters" feature
* of the search box. Returns an array of arrays with 'id' and 'value' keys used
* for generating hidden checkboxes.
*
* @param array $filterList Standard filter information
* @param array $checkboxFilters Checkbox filter information
*
* @return array
*/
public function getFilterDetails($filterList, $checkboxFilters)
{
$results = array();
$i = 0;
foreach ($filterList as $field => $data) {
foreach ($data as $value) {
$results[] = array(
'id' => 'applied_filter_' . ++$i,
'value' => "$field:\"$value\""
);
}
}
$i = 0;
foreach ($checkboxFilters as $current) {
if ($current['selected']) {
$results[] = array(
'id' => 'applied_checkbox_filter_' . ++$i,
'value' => $current['filter']
);
}
}
return $results;
}
}
\ No newline at end of file
...@@ -55,19 +55,6 @@ ...@@ -55,19 +55,6 @@
<a href="<?=$this->url($advSearch)?>" class="small"><?=$this->transEsc("Advanced")?></a> <a href="<?=$this->url($advSearch)?>" class="small"><?=$this->transEsc("Advanced")?></a>
<? endif; ?> <? endif; ?>
<?
/* Do we have any checkbox filters? */
$hasCheckboxFilters = false;
if (isset($this->checkboxFilters) && count($this->checkboxFilters) > 0) {
foreach ($this->checkboxFilters as $current) {
if ($current['selected']) {
$hasCheckboxFilters = true;
break;
}
}
}
?>
<? $shards = $options->getShards(); if ($options->showShardCheckboxes() && !empty($shards)): ?> <? $shards = $options->getShards(); if ($options->showShardCheckboxes() && !empty($shards)): ?>
<? <?
$selectedShards = isset($this->selectedShards) $selectedShards = isset($this->selectedShards)
...@@ -79,27 +66,21 @@ ...@@ -79,27 +66,21 @@
<input type="checkbox" <?=$isSelected ? 'checked="checked" ' : ''?>name="shard[]" value='<?=$this->escapeHtml($shard)?>' /> <?=$this->transEsc($shard)?> <input type="checkbox" <?=$isSelected ? 'checked="checked" ' : ''?>name="shard[]" value='<?=$this->escapeHtml($shard)?>' /> <?=$this->transEsc($shard)?>
<? endforeach; ?> <? endforeach; ?>
<? endif; ?> <? endif; ?>
<? if ((isset($this->filterList) && is_array($this->filterList) && count($this->filterList) > 0) || $hasCheckboxFilters): ?> <?
$filterDetails = $this->searchbox()->getFilterDetails(
isset($this->filterList) && is_array($this->filterList) ? $this->filterList : array(),
isset($this->checkboxFilters) && is_array($this->checkboxFilters) ? $this->checkboxFilters : array()
);
?>
<? if (!empty($filterDetails)): ?>
<? $defaultFilterState = $options->getRetainFilterSetting() ? ' checked="checked"' : ''; ?> <? $defaultFilterState = $options->getRetainFilterSetting() ? ' checked="checked"' : ''; ?>
<div class="keepFilters"> <div class="keepFilters">
<input type="checkbox"<?=$defaultFilterState?> id="searchFormKeepFilters"/> <label for="searchFormKeepFilters"><?=$this->transEsc("basic_search_keep_filters")?></label> <input type="checkbox"<?=$defaultFilterState?> id="searchFormKeepFilters"/> <label for="searchFormKeepFilters"><?=$this->transEsc("basic_search_keep_filters")?></label>
<div class="offscreen"> <div class="offscreen">
<? if (isset($this->filterList) && is_array($this->filterList)): ?> <? foreach ($filterDetails as $current): ?>
<? $i = 0; foreach ($this->filterList as $field => $data): ?> <input id="<?=$this->escapeHtml($current['id'])?>" type="checkbox"<?=$defaultFilterState?> name="filter[]" value="<?=$this->escapeHtml($current['value'])?>" />
<? foreach ($data as $value): ?> <label for="<?=$this->escapeHtml($current['id'])?>"><?=$this->escapeHtml($current['value'])?></label>
<input id="applied_filter_<?=++$i?>" type="checkbox"<?=$defaultFilterState?> name="filter[]" value="<?=$this->escapeHtml($field)?>:&quot;<?=$this->escapeHtml($value)?>&quot;" /> <? endforeach; ?>
<label for="applied_filter_<?=$i?>"><?=$this->escapeHtml($field)?>:&quot;<?=$this->escapeHtml($value)?>&quot;</label>
<? endforeach; ?>
<? endforeach; ?>
<? endif; ?>
<? if ($hasCheckboxFilters): ?>
<? $i = 0; foreach ($checkboxFilters as $current): ?>
<? if ($current['selected']): ?>
<input id="applied_checkbox_filter_<?=++$i?>" type="checkbox"<?=$defaultFilterState?> name="filter[]" value="<?=$this->escapeHtml($current['filter'])?>" />
<label for="applied_checkbox_filter_<?=$i?>"><?=$this->escapeHtml($current['filter'])?></label>
<? endif; ?>
<? endforeach; ?>
<? endif; ?>
</div> </div>
</div> </div>
<? endif; ?> <? endif; ?>
......
...@@ -103,6 +103,9 @@ return array( ...@@ -103,6 +103,9 @@ return array(
$sm->getServiceLocator()->get('VuFind\Config')->get('config') $sm->getServiceLocator()->get('VuFind\Config')->get('config')
); );
}, },
'searchbox' => function ($sm) {
return new \VuFind\View\Helper\Root\SearchBox();
},
'searchoptions' => function ($sm) { 'searchoptions' => function ($sm) {
return new VuFind\View\Helper\Root\SearchOptions( return new VuFind\View\Helper\Root\SearchOptions(
$sm->getServiceLocator()->get('VuFind\SearchOptionsPluginManager') $sm->getServiceLocator()->get('VuFind\SearchOptionsPluginManager')
......
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