From 54085f46e08234f26a905b1bb71f1d320abce2da Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 23 May 2014 09:43:40 -0400
Subject: [PATCH] Summon advanced checkbox facet support. - On by default, with
 upgrade support + test

---
 config/vufind/Summon.ini                              |  9 ++++++++-
 module/VuFind/src/VuFind/Config/Upgrade.php           | 11 +++++++++++
 .../VuFind/src/VuFind/Controller/SummonController.php |  5 +++++
 .../unit-tests/src/VuFindTest/Config/UpgradeTest.php  |  7 +++++++
 .../blueprint/templates/search/advanced/summon.phtml  |  9 ++++++++-
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/config/vufind/Summon.ini b/config/vufind/Summon.ini
index b3cd8a2565e..91312983d85 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/module/VuFind/src/VuFind/Config/Upgrade.php b/module/VuFind/src/VuFind/Config/Upgrade.php
index 282ff5bcecf..c97adc07b75 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/SummonController.php b/module/VuFind/src/VuFind/Controller/SummonController.php
index 888d33113bf..0097f11a5e9 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/unit-tests/src/VuFindTest/Config/UpgradeTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Config/UpgradeTest.php
index 2158a0de2ce..83bb5029a33 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/summon.phtml b/themes/blueprint/templates/search/advanced/summon.phtml
index 7ba27ada0a7..9f15eda7923 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>
-- 
GitLab