diff --git a/config/vufind/Summon.ini b/config/vufind/Summon.ini index b3cd8a2565e41883c406c0b94abfa595ae4bbd85..91312983d8580a3d95f282e3ca12681006dbe67b 100644 --- a/config/vufind/Summon.ini +++ b/config/vufind/Summon.ini @@ -162,13 +162,20 @@ facet_limit = 100 ; how many values should we show for each facet? ; 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 ; colon separated list; e.g. "daterange:field1:field2:field3" ; genericrange - just like daterange above, but for genericRange[] fields. ; numericrange - just like daterange above, but for numericRange[] fields. -special_facets = daterange +special_facets = "daterange,checkboxes:Summon" ; Should we OR together facets rather than ANDing them? Set to * for ; all facets, use a comma-separated list to apply to some of the facets, set ; to false or omit to disable ORed facets. 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/Config/Upgrade.php b/module/VuFind/src/VuFind/Config/Upgrade.php index 282ff5bcecf87d3628cf879ab997374cbe664e4e..c97adc07b756fbaf501b2d99b2b7519cbec79bd4 100644 --- a/module/VuFind/src/VuFind/Config/Upgrade.php +++ b/module/VuFind/src/VuFind/Config/Upgrade.php @@ -744,6 +744,17 @@ class Upgrade ); $this->applyOldSettings('Summon.ini', $groups); + // Turn on advanced checkbox facets if we're upgrading from a version + // prior to 2.3. + if ((float)$this->from < 2.3) { + $cfg = & $this->newConfigs['Summon.ini']['Advanced_Facet_Settings']; + if (!isset($cfg['special_facets']) || empty($cfg['special_facets'])) { + $cfg['special_facets'] = 'checkboxes:Summon'; + } else if (false === strpos('checkboxes', $cfg['special_facets'])) { + $cfg['special_facets'] .= ',checkboxes:Summon'; + } + } + // save the file $this->saveModifiedConfig('Summon.ini'); } 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/module/VuFind/src/VuFind/Controller/SummonController.php b/module/VuFind/src/VuFind/Controller/SummonController.php index 888d33113bf5fb1b6726feab37570a8b84c12170..0097f11a5e9e052ee3cad6ba9807f3dc4b28e060 100644 --- a/module/VuFind/src/VuFind/Controller/SummonController.php +++ b/module/VuFind/src/VuFind/Controller/SummonController.php @@ -101,6 +101,11 @@ class SummonController extends AbstractSearch $specialFacets = $this->parseSpecialFacetsSetting( $view->options->getSpecialAdvancedFacets() ); + if (isset($specialFacets['checkboxes'])) { + $view->checkboxFacets = $this->processAdvancedCheckboxes( + $specialFacets['checkboxes'], $view->saved + ); + } $view->ranges = $this ->getAllRangeSettings($specialFacets, $view->saved, 'Summon'); diff --git a/module/VuFind/tests/fixtures/configs/1.1/config.ini b/module/VuFind/tests/fixtures/configs/1.1/config.ini index 7e1aff3ce06fd0de141232dfdbce763cfb1b2e0b..66d89a7107d0d93cda74d9a6882268675f9e176e 100644 --- a/module/VuFind/tests/fixtures/configs/1.1/config.ini +++ b/module/VuFind/tests/fixtures/configs/1.1/config.ini @@ -241,9 +241,9 @@ pw = "Password" ;side_recommend[] = CatalogResults:lookfor ; Summon is Optional. See also the separate Summon.ini file. -;[Summon] -;apiId = myAccessId -;apiKey = mySecretKey +[Summon] +apiId = myAccessId +apiKey = mySecretKey ; WorldCat is Optional. Worldcat offers extra features such as "Other Editions" ; and the WorldCat searching. diff --git a/module/VuFind/tests/fixtures/configs/1.2/config.ini b/module/VuFind/tests/fixtures/configs/1.2/config.ini index ee9c8cb5f3c42db3905571190c2bd298bdbd729b..dd0cb96afff94f7645e5b3df8ab706a66aa7a4ff 100644 --- a/module/VuFind/tests/fixtures/configs/1.2/config.ini +++ b/module/VuFind/tests/fixtures/configs/1.2/config.ini @@ -275,9 +275,9 @@ pw = "Password" ;side_recommend[] = CatalogResults:lookfor ; Summon is Optional. See also the separate Summon.ini file. -;[Summon] -;apiId = myAccessId -;apiKey = mySecretKey +[Summon] +apiId = myAccessId +apiKey = mySecretKey ; WorldCat is Optional. Worldcat offers extra features such as "Other Editions" ; and the WorldCat searching. diff --git a/module/VuFind/tests/fixtures/configs/1.3/config.ini b/module/VuFind/tests/fixtures/configs/1.3/config.ini index da980b0ef6cd3465dd93d4ba5d4039553069ad47..1672da3ab2931dc0ab50c55f3d8c6393572878c6 100644 --- a/module/VuFind/tests/fixtures/configs/1.3/config.ini +++ b/module/VuFind/tests/fixtures/configs/1.3/config.ini @@ -337,9 +337,9 @@ pw = "Password" ;side_recommend[] = CatalogResults:lookfor ; Summon is Optional. See also the separate Summon.ini file. -;[Summon] -;apiId = myAccessId -;apiKey = mySecretKey +[Summon] +apiId = myAccessId +apiKey = mySecretKey ; WorldCat is Optional. Worldcat offers extra features such as "Other Editions" ; and the WorldCat searching. diff --git a/module/VuFind/tests/fixtures/configs/1.4/config.ini b/module/VuFind/tests/fixtures/configs/1.4/config.ini index ae09cd7de81603ad10b682058eb34025f18a9245..abf8ebf8d954c672e0852e30d28e4a359c640ee5 100644 --- a/module/VuFind/tests/fixtures/configs/1.4/config.ini +++ b/module/VuFind/tests/fixtures/configs/1.4/config.ini @@ -413,9 +413,9 @@ pw = "Password" ;side_recommend[] = CatalogResults:lookfor ; Summon is Optional. See also the separate Summon.ini file. -;[Summon] -;apiId = myAccessId -;apiKey = mySecretKey +[Summon] +apiId = myAccessId +apiKey = mySecretKey ; WorldCat is Optional. Worldcat offers extra features such as "Other Editions" ; and the WorldCat searching. diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php index 2158a0de2ce46dd979a78a1031e0570cccaaa4c8..83bb5029a33af732454c705374f66cfae51621a0 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php @@ -109,6 +109,13 @@ class UpgradeTest extends \VuFindTest\Unit\TestCase $this->assertEquals(0, count($warnings)); } + // Summon should always have the checkboxes setting turned on after + // upgrade: + $this->assertEquals( + 'daterange,checkboxes:Summon', + $results['Summon.ini']['Advanced_Facet_Settings']['special_facets'] + ); + // Make sure the obsolete Index/local setting is removed: $this->assertFalse(isset($results['config.ini']['Index']['local'])); 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> diff --git a/themes/blueprint/templates/search/advanced/summon.phtml b/themes/blueprint/templates/search/advanced/summon.phtml index 7ba27ada0a79fd4c5d4f262a89a1c796e25a08a9..9f15eda79237f85dc0900dcf0901ad0a2bfb23e0 100644 --- a/themes/blueprint/templates/search/advanced/summon.phtml +++ b/themes/blueprint/templates/search/advanced/summon.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="span-5"> <label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>"><?=$this->transEsc($list['label'])?>:</label> diff --git a/themes/bootstrap/templates/search/advanced/checkbox-filters.phtml b/themes/bootstrap/templates/search/advanced/checkbox-filters.phtml new file mode 100644 index 0000000000000000000000000000000000000000..cf8c22b72ccf6f496fa618128ddccb85e7b8c687 --- /dev/null +++ b/themes/bootstrap/templates/search/advanced/checkbox-filters.phtml @@ -0,0 +1,12 @@ +<? if (isset($this->checkboxFacets) && count($this->checkboxFacets) > 0): ?> + <fieldset> + <? foreach ($this->checkboxFacets as $current): ?> + <div class="checkboxFilter"> + <label class="checkbox"> + <input type="checkbox" name="filter[]" value="<?=$this->escapeHtml($current['filter'])?>" id="<?=$this->escapeHtml(str_replace(' ', '', $current['desc']))?>"<? if ($current['selected']): ?> checked="checked"<? endif; ?>/> + <?=$this->transEsc($current['desc'])?> + </label> + </div> + <? endforeach; ?> + </fieldset> +<?endif;?> \ No newline at end of file diff --git a/themes/bootstrap/templates/search/advanced/solr.phtml b/themes/bootstrap/templates/search/advanced/solr.phtml index 74b0572f8a2c8f144dc080e75444a7e5287c2a2d..e7723c85f5d427d37516258779fac264585fcf1f 100644 --- a/themes/bootstrap/templates/search/advanced/solr.phtml +++ b/themes/bootstrap/templates/search/advanced/solr.phtml @@ -1,5 +1,12 @@ -<? if (!empty($this->facetList)): ?> +<? if (!empty($this->facetList) || !empty($this->checkboxFacets)): ?> <p class="lead"><?=$this->transEsc('Limit To')?></p> +<? endif; ?> + +<? if (!empty($this->checkboxFacets)): ?> + <?=$this->render('search/advanced/checkbox-filters.phtml')?> +<? endif; ?> + +<? if (!empty($this->facetList)): ?> <div class="row-fluid"> <? foreach ($this->facetList as $field => $list): ?> <div class="span<?=floor(12/count($this->facetList)) ?>"> diff --git a/themes/bootstrap/templates/search/advanced/summon.phtml b/themes/bootstrap/templates/search/advanced/summon.phtml index ce28d09242d819e1630f837fb04d2ee44f346e18..3102e37bec83a8133293ec0b3d26d651104a7e3d 100644 --- a/themes/bootstrap/templates/search/advanced/summon.phtml +++ b/themes/bootstrap/templates/search/advanced/summon.phtml @@ -1,19 +1,26 @@ +<? if (!empty($this->facetList) || !empty($this->checkboxFacets)): ?> + <p class="lead"><?=$this->transEsc('Limit To')?></p> +<? endif; ?> + +<? if (!empty($this->checkboxFacets)): ?> + <?=$this->render('search/advanced/checkbox-filters.phtml')?> +<? endif; ?> + <? if (!empty($this->facetList)): ?> - <h3><?=$this->transEsc('Limit To')?></h3> <div class="row-fluid"> <? foreach ($this->facetList as $field => $list): ?> <div class="span<?=floor(12/count($this->facetList)) ?>"> <label class="displayBlock" for="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>"><?=$this->transEsc($list['label'])?>:</label> <select class="span12" id="limit_<?=$this->escapeHtml(str_replace(' ', '', $field))?>" name="filter[]" multiple="multiple" size="10"> <? - // Sort the current facet list alphabetically; we'll use this data - // along with the foreach below to display facet options in the - // correct order. - $sorted = array(); - foreach ($list['list'] as $i => $value) { - $sorted[$i] = $value['displayText']; - } - natcasesort($sorted); + // Sort the current facet list alphabetically; we'll use this data + // along with the foreach below to display facet options in the + // correct order. + $sorted = array(); + foreach ($list['list'] as $i => $value) { + $sorted[$i] = $value['displayText']; + } + natcasesort($sorted); ?> <? foreach ($sorted as $i => $display): ?> <? $value = $list['list'][$i]; ?>