From 6d1b37f23ab8850876a2ca9309b01e894fb30f54 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 28 Feb 2014 12:25:54 -0500 Subject: [PATCH] Implemented activateAllFacets() for Summon\Params. - Refactored some shared functionality to Base\Params. --- .../VuFind/src/VuFind/Search/Base/Params.php | 29 +++++++++++++++++++ .../VuFind/src/VuFind/Search/Solr/Params.php | 19 ++---------- .../src/VuFind/Search/Summon/Params.php | 17 +++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php index 071ac740450..b945bc619ec 100644 --- a/module/VuFind/src/VuFind/Search/Base/Params.php +++ b/module/VuFind/src/VuFind/Search/Base/Params.php @@ -1428,4 +1428,33 @@ class Params implements ServiceLocatorAwareInterface } return $this->query; } + + /** + * Initialize facet settings for the specified configuration sections. + * + * @param string $facetList Config section containing fields to activate + * @param string $facetSettings Config section containing related settings + * @param string $cfgFile Name of configuration to load + * + * @return bool True if facets set, false if no settings found + */ + protected function initFacetList($facetList, $facetSettings, $cfgFile = 'facets') + { + $config = $this->getServiceLocator()->get('VuFind\Config')->get($cfgFile); + if (!isset($config->$facetList)) { + return false; + } + if (isset($config->$facetSettings->orFacets)) { + $orFields + = array_map('trim', explode(',', $config->$facetSettings->orFacets)); + } else { + $orFields = array(); + } + foreach ($config->$facetList as $key => $value) { + $useOr = (isset($orFields[0]) && $orFields[0] == '*') + || in_array($key, $orFields); + $this->addFacet($key, $value, $useOr); + } + return true; + } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php index 4454b808943..e6c44bd8526 100644 --- a/module/VuFind/src/VuFind/Search/Solr/Params.php +++ b/module/VuFind/src/VuFind/Search/Solr/Params.php @@ -234,32 +234,19 @@ class Params extends \VuFind\Search\Base\Params * * @param string $facetList Config section containing fields to activate * @param string $facetSettings Config section containing related settings + * @param string $cfgFile Name of configuration to load * * @return bool True if facets set, false if no settings found */ - protected function initFacetList($facetList, $facetSettings) + protected function initFacetList($facetList, $facetSettings, $cfgFile = 'facets') { $config = $this->getServiceLocator()->get('VuFind\Config')->get('facets'); - if (!isset($config->$facetList)) { - return false; - } - if (isset($config->$facetSettings->orFacets)) { - $orFields - = array_map('trim', explode(',', $config->$facetSettings->orFacets)); - } else { - $orFields = array(); - } - foreach ($config->$facetList as $key => $value) { - $useOr = (isset($orFields[0]) && $orFields[0] == '*') - || in_array($key, $orFields); - $this->addFacet($key, $value, $useOr); - } if (isset($config->$facetSettings->facet_limit) && is_numeric($config->$facetSettings->facet_limit) ) { $this->setFacetLimit($config->$facetSettings->facet_limit); } - return true; + return parent::initFacetList($facetList, $facetSettings, $cfgFile); } /** diff --git a/module/VuFind/src/VuFind/Search/Summon/Params.php b/module/VuFind/src/VuFind/Search/Summon/Params.php index 04c56fef9d8..9cde5cc1bcb 100644 --- a/module/VuFind/src/VuFind/Search/Summon/Params.php +++ b/module/VuFind/src/VuFind/Search/Summon/Params.php @@ -296,4 +296,21 @@ class Params extends \VuFind\Search\Base\Params return $filter; } + + /** + * Load all available facet settings. This is mainly useful for showing + * appropriate labels when an existing search has multiple filters associated + * with it. + * + * @param string $preferredSection Section to favor when loading settings; if + * multiple sections contain the same facet, this section's description will + * be favored. + * + * @return void + */ + public function activateAllFacets($preferredSection = false) + { + $this->initFacetList('Facets', 'Results_Settings', 'Summon'); + $this->initFacetList('Advanced_Facets', 'Advanced_Facet_Settings', 'Summon'); + } } \ No newline at end of file -- GitLab