diff --git a/config/vufind/facets.ini b/config/vufind/facets.ini index ca6ad3793b067bc279d5c26f1245a6efc6415cc9..2a8e848bb477b3aecc9ce0bf94354cbe68c702bc 100644 --- a/config/vufind/facets.ini +++ b/config/vufind/facets.ini @@ -90,6 +90,13 @@ orFacets = * ; 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. ; 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 ; [Special_Facets] above; if multiple fields are specified above but you ; only want certain ones on the advanced screen, you can filter with a @@ -99,10 +106,10 @@ orFacets = * ; numericrange - just like daterange above, but for numericRange[] fields. 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 ; 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_facets[] = institution ;translated_facets[] = building diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index e8bdeb640e1dafeb15a31948f97ea9139caafd8a..44a6c152f2209754beae2967bec0adb053809f65 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -553,4 +553,50 @@ class AbstractSearch extends AbstractBase } 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 diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index d9253a917c1da5404baf8d360529ddad664392b2..820d27062ca758bbb9599b4027a2a0264f1e8aad 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -61,7 +61,13 @@ class SearchController extends AbstractSearch $view->illustratedLimit = $this->getIllustrationSettings($view->saved); } + if (isset($specialFacets['checkboxes'])) { + $view->checkboxFacets = $this->processAdvancedCheckboxes( + $specialFacets['checkboxes'], $view->saved + ); + } $view->ranges = $this->getAllRangeSettings($specialFacets, $view->saved); + return $view; } diff --git a/themes/blueprint/templates/search/advanced/checkbox-filters.phtml b/themes/blueprint/templates/search/advanced/checkbox-filters.phtml new file mode 100644 index 0000000000000000000000000000000000000000..1eba661ad22d9c5a0d134bf94f038c4db19aadea --- /dev/null +++ b/themes/blueprint/templates/search/advanced/checkbox-filters.phtml @@ -0,0 +1,13 @@ +<? 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;?> diff --git a/themes/blueprint/templates/search/advanced/solr.phtml b/themes/blueprint/templates/search/advanced/solr.phtml index f5d19893f0cfe914c027e3c2971d92f1043dc479..632c525c0a2a5778c1b6d272c0e7a59e9111b85f 100644 --- a/themes/blueprint/templates/search/advanced/solr.phtml +++ b/themes/blueprint/templates/search/advanced/solr.phtml @@ -1,5 +1,12 @@ -<? if (!empty($this->facetList)): ?> +<? if (!empty($this->facetList) || !empty($this->checkboxFacets)): ?> <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): ?> <div class="<?=($field=='callnumber-first')?'span-7':'span-4'?>"> <label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>"><?=$this->transEsc($list['label'])?>:</label>