From 397d741c5ffcbb33a10f364400846a08ecfec192 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 16 May 2014 10:17:18 -0400
Subject: [PATCH] Added mechanism for suppressing display of certain filters.

---
 .../src/VuFind/Recommend/SideFacets.php       | 33 +++++++++++++++++++
 .../templates/Recommend/SideFacets.phtml      |  4 +--
 .../templates/Recommend/SideFacets.phtml      |  4 +--
 .../templates/Recommend/SideFacets.phtml      |  2 +-
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/module/VuFind/src/VuFind/Recommend/SideFacets.php b/module/VuFind/src/VuFind/Recommend/SideFacets.php
index 158d1256cb1..96fca96f5eb 100644
--- a/module/VuFind/src/VuFind/Recommend/SideFacets.php
+++ b/module/VuFind/src/VuFind/Recommend/SideFacets.php
@@ -253,6 +253,39 @@ class SideFacets extends AbstractFacets
         return array_map('trim', explode(',', $this->collapsedFacets));
     }
 
+    /**
+     * Get the list of filters to display
+     *
+     * @param array $extraFilters Extra filters to add to the list.
+     *
+     * @return array
+     */
+    public function getVisibleFilters($extraFilters = array())
+    {
+        // Merge extras into main list:
+        $filterList = array_merge(
+            $this->results->getParams()->getFilterList(true), $extraFilters
+        );
+
+        // Filter out suppressed values:
+        $final = array();
+        foreach ($filterList as $field => $filters) {
+            $current = array();
+            foreach ($filters as $i => $filter) {
+                if (!isset($filter['suppressDisplay'])
+                    || !$filter['suppressDisplay']
+                ) {
+                    $current[] = $filter;
+                }
+            }
+            if (!empty($current)) {
+                $final[$field] = $current;
+            }
+        }
+
+        return $final;
+    }
+
     /**
      * getRangeFacets
      *
diff --git a/themes/blueprint/templates/Recommend/SideFacets.phtml b/themes/blueprint/templates/Recommend/SideFacets.phtml
index 91a056b0039..b73a7bcd11f 100644
--- a/themes/blueprint/templates/Recommend/SideFacets.phtml
+++ b/themes/blueprint/templates/Recommend/SideFacets.phtml
@@ -11,9 +11,9 @@
         </div>
     <? endforeach; ?>
   <? endif; ?>
-  <? $extraFilters = isset($this->extraSideFacetFilters) ? $this->extraSideFacetFilters : array(); ?>
   <? $collapsedFacets = $this->recommend->getCollapsedFacets() ?>
-  <? $filterList = array_merge($results->getParams()->getFilterList(true), $extraFilters); if (!empty($filterList)): ?>
+  <? $extraFilters = isset($this->extraSideFacetFilters) ? $this->extraSideFacetFilters : array(); ?>
+  <? $filterList = $this->recommend->getVisibleFilters($extraFilters); if (!empty($filterList)): ?>
     <strong><?=$this->transEsc('Remove Filters')?></strong>
     <ul class="filters">
     <? foreach ($filterList as $field => $filters): ?>
diff --git a/themes/bootstrap/templates/Recommend/SideFacets.phtml b/themes/bootstrap/templates/Recommend/SideFacets.phtml
index f8047a75893..09915b710c1 100644
--- a/themes/bootstrap/templates/Recommend/SideFacets.phtml
+++ b/themes/bootstrap/templates/Recommend/SideFacets.phtml
@@ -14,9 +14,9 @@
     </div>
   <? endforeach; ?>
 <? endif; ?>
-<? $extraFilters = isset($this->extraSideFacetFilters) ? $this->extraSideFacetFilters : array(); ?>
 <? $collapsedFacets = $this->recommend->getCollapsedFacets() ?>
-<? $filterList = array_merge($results->getParams()->getFilterList(true), $extraFilters); if (!empty($filterList)): ?>
+<? $extraFilters = isset($this->extraSideFacetFilters) ? $this->extraSideFacetFilters : array(); ?>
+<? $filterList = $this->recommend->getVisibleFilters($extraFilters); if (!empty($filterList)): ?>
   <ul class="nav nav-list">
     <li class="nav-header"><?=$this->transEsc('Remove Filters')?></li>
     <? foreach ($filterList as $field => $filters): ?>
diff --git a/themes/jquerymobile/templates/Recommend/SideFacets.phtml b/themes/jquerymobile/templates/Recommend/SideFacets.phtml
index bb69c5fefdd..e93c5c27218 100644
--- a/themes/jquerymobile/templates/Recommend/SideFacets.phtml
+++ b/themes/jquerymobile/templates/Recommend/SideFacets.phtml
@@ -1,5 +1,5 @@
 <? $results = $this->recommend->getResults(); ?>
-<? $filterList = $results->getParams()->getFilterList(true); if (!empty($filterList)): ?>
+<? $filterList = $this->recommend->getVisibleFilters(); if (!empty($filterList)): ?>
   <ul class="filters" data-role="listview" data-inset="true" data-dividertheme="e">
     <li data-role="list-divider"><?=$this->transEsc('adv_search_filters')?></li>
     <? $i = 0; foreach ($filterList as $field => $filters): ?>
-- 
GitLab