Skip to content
Snippets Groups Projects
Commit fdf3a954 authored by Luke O'Sullivan's avatar Luke O'Sullivan Committed by Demian Katz
Browse files

Add checkbox facets to advanced search screen.

parent 5a1be070
No related merge requests found
...@@ -90,6 +90,13 @@ orFacets = * ...@@ -90,6 +90,13 @@ orFacets = *
; Some facet types don't lend themselves to this format, and they can be turned on ; Some facet types don't lend themselves to this format, and they can be turned on
; by inclusion in the comma-separated list below, or turned off by being excluded. ; by inclusion in the comma-separated list below, or turned off by being excluded.
; Supported values: ; Supported values:
; checkboxes - displays a list of checkbox facets as specified in the
; [CheckboxFacets] section above. You can specify the config file/section
; with colon-separated parameters following the checkboxes setting; e.g.
; checkboxes:facets:myCustomCheckboxes will load from the myCustomCheckboxes
; section of facets.ini. You can prefix the section name with a tilde (~)
; to reverse processing of the section to label => filter format (useful if your
; filters contain values that are illegal in configuration keys -- e.g. []).
; daterange - for the range controls specified by the dateRange setting under ; daterange - for the range controls specified by the dateRange setting under
; [Special_Facets] above; if multiple fields are specified above but you ; [Special_Facets] above; if multiple fields are specified above but you
; only want certain ones on the advanced screen, you can filter with a ; only want certain ones on the advanced screen, you can filter with a
...@@ -99,10 +106,10 @@ orFacets = * ...@@ -99,10 +106,10 @@ orFacets = *
; numericrange - just like daterange above, but for numericRange[] fields. ; numericrange - just like daterange above, but for numericRange[] fields.
special_facets = "illustrated,daterange" special_facets = "illustrated,daterange"
; Any facets named in the list below will have their values run through the ; Any facets named in the list below will have their values run through the
; translation code; unlisted facets will displayed as-is without translation. For ; translation code; unlisted facets will displayed as-is without translation. For
; translated facets, be sure that all of the necessary strings are included in the ; translated facets, be sure that all of the necessary strings are included in the
; language files found in the web/lang directory. By default, no facets are ; language files found in the web/lang directory. By default, no facets are
; translated -- uncomment or add lines below to turn on this feature. ; translated -- uncomment or add lines below to turn on this feature.
;translated_facets[] = institution ;translated_facets[] = institution
;translated_facets[] = building ;translated_facets[] = building
......
...@@ -553,4 +553,50 @@ class AbstractSearch extends AbstractBase ...@@ -553,4 +553,50 @@ class AbstractSearch extends AbstractBase
} }
return $parsed; return $parsed;
} }
/**
* Process the checkbox setting from special facets.
*
* @param array $params Parameters to the checkbox setting
* @param object $savedSearch Saved search object (false if none)
*
* @return array
*/
protected function processAdvancedCheckboxes($params, $savedSearch = false)
{
// Set defaults for missing parameters:
$config = isset($params[0]) ? $params[0] : 'facets';
$section = isset($params[1]) ? $params[1] : 'CheckboxFacets';
// Load config file:
$config = $this->getServiceLocator()->get('VuFind\Config')->get($config);
// Process checkbox settings in config:
if (substr($section, 0, 1) == '~') { // reverse flag
$section = substr($section, 1);
$flipCheckboxes = true;
}
$checkboxFacets = ($section && isset($config->$section))
? $config->$section->toArray() : array();
if (isset($flipCheckboxes) && $flipCheckboxes) {
$checkboxFacets = array_flip($checkboxFacets);
}
// Reformat for convenience:
$formatted = array();
foreach ($checkboxFacets as $filter => $desc) {
$current = compact("desc", "filter");
$current['selected']
= $savedSearch && $savedSearch->getParams()->hasFilter($filter);
// We don't want to double-display checkboxes on advanced search, so
// if they are checked, we should remove them from the object to
// prevent display in the "other filters" area.
if ($current['selected']) {
$savedSearch->getParams()->removeFilter($filter);
}
$formatted[] = $current;
}
return $formatted;
}
} }
\ No newline at end of file
...@@ -61,7 +61,13 @@ class SearchController extends AbstractSearch ...@@ -61,7 +61,13 @@ class SearchController extends AbstractSearch
$view->illustratedLimit $view->illustratedLimit
= $this->getIllustrationSettings($view->saved); = $this->getIllustrationSettings($view->saved);
} }
if (isset($specialFacets['checkboxes'])) {
$view->checkboxFacets = $this->processAdvancedCheckboxes(
$specialFacets['checkboxes'], $view->saved
);
}
$view->ranges = $this->getAllRangeSettings($specialFacets, $view->saved); $view->ranges = $this->getAllRangeSettings($specialFacets, $view->saved);
return $view; return $view;
} }
......
<? if (isset($this->checkboxFacets) && count($this->checkboxFacets) > 0): ?>
<div class="span-7">
<fieldset>
<? foreach ($this->checkboxFacets as $current): ?>
<div class="checkboxFilter">
<input type="checkbox" name="filter[]" value="<?=$this->escapeHtml($current['filter'])?>" id="<?=$this->escapeHtml(str_replace(' ', '', $current['desc']))?>" <? if ($current['selected']): ?>checked="checked" <? endif; ?> />
<label for="<?=$this->escapeHtml(str_replace(' ', '', $current['desc']))?>"><?=$this->transEsc($current['desc'])?></label>
</div>
<? endforeach; ?>
</fieldset>
</div>
<div class="clear"></div>
<?endif;?>
<? if (!empty($this->facetList)): ?> <? if (!empty($this->facetList) || !empty($this->checkboxFacets)): ?>
<h3><?=$this->transEsc('Limit To')?></h3> <h3><?=$this->transEsc('Limit To')?></h3>
<? endif; ?>
<? if (!empty($this->checkboxFacets)): ?>
<?=$this->render('search/advanced/checkbox-filters.phtml')?>
<? endif; ?>
<? if (!empty($this->facetList)): ?>
<? foreach ($this->facetList as $field => $list): ?> <? foreach ($this->facetList as $field => $list): ?>
<div class="<?=($field=='callnumber-first')?'span-7':'span-4'?>"> <div class="<?=($field=='callnumber-first')?'span-7':'span-4'?>">
<label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>"><?=$this->transEsc($list['label'])?>:</label> <label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>"><?=$this->transEsc($list['label'])?>:</label>
......
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