diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 9c0febe09ebd27acb61d887a2b9a3495c1156173..dc4d52b23c31809d42a6b86b04c32033e6253497 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -1489,6 +1489,10 @@ rtl_langs = "ar,he" ; have a large index! [Browse] result_limit = 100 + +; These settings can be used to turn specific browse types on or off; the order +; of the settings in the configuration below will also control the order of the +; options displayed in the web interface: tag = true ; allow browsing of Tags dewey = false ; allow browsing of Dewey Decimal call numbers lcc = true ; allow browsing of LC call numbers @@ -1497,6 +1501,7 @@ topic = true ; allow browsing of subject headings genre = true ; allow browsing of genre subdivisions region = true ; allow browsing of region subdivisions era = true ; allow browsing of era subdivisions + ; You can use this setting to change the default alphabet provided for browsing: ;alphabet_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Uncomment to sort lists alphabetically (instead of by popularity); note that diff --git a/module/VuFind/src/VuFind/Controller/BrowseController.php b/module/VuFind/src/VuFind/Controller/BrowseController.php index c32ca4fda1b6be6b302ac9494497437ff1e16b30..e609c487d9ca9b818d7f269272c1ee882813caeb 100644 --- a/module/VuFind/src/VuFind/Controller/BrowseController.php +++ b/module/VuFind/src/VuFind/Controller/BrowseController.php @@ -106,6 +106,79 @@ class BrowseController extends AbstractBase return $this->currentAction; } + /** + * Determine which browse options to display, and in which order. Returns an + * array of browse options in the configured order. + * + * @return array + */ + protected function getActiveBrowseOptions() + { + // Get a list of all of the options mentioned in config.ini: + $browseConfig = $this->config->Browse->toArray(); + $configuredOptions = array_keys($browseConfig); + + // This is a list of all available browse options: + $allOptions = [ + 'tag', 'dewey', 'lcc', 'author', 'topic', 'genre', 'region', 'era' + ]; + + // By default, all options except dewey are turned on if omitted from config: + $defaultOptions = array_diff($allOptions, ['dewey']); + + // This is a callback function for array_filter, which will filter out any + // settings set to false in config.ini: + $filter = function ($option) use ($browseConfig) { + return (bool)($browseConfig[$option] ?? false); + }; + + // The active options are a list of configured settings set to true in + // config.ini, merged with any default options that were not configured in + // config.ini at all: + return array_merge( + array_filter(array_intersect($configuredOptions, $allOptions), $filter), + array_diff($defaultOptions, $configuredOptions) + ); + } + + /** + * Given a list of active options, format them into details for the view. + * + * @return array + */ + protected function buildBrowseOptions() + { + // Initialize the array of top-level browse options. + $browseOptions = []; + + $activeOptions = $this->getActiveBrowseOptions(); + foreach ($activeOptions as $option) { + switch ($option) { + case 'dewey': + $deweyLabel = in_array('lcc', $activeOptions) + ? 'browse_dewey' : 'Call Number'; + $browseOptions[] = $this->buildBrowseOption('Dewey', $deweyLabel); + break; + case 'lcc': + $lccLabel = in_array('dewey', $activeOptions) + ? 'browse_lcc' : 'Call Number'; + $browseOptions[] = $this->buildBrowseOption('LCC', $lccLabel); + break; + case 'tag': + if ($this->tagsEnabled()) { + $browseOptions[] = $this->buildBrowseOption('Tag', 'Tag'); + } + break; + default: + $current = ucwords($option); + $browseOptions[] = $this->buildBrowseOption($current, $current); + break; + } + } + + return $browseOptions; + } + /** * Create a new ViewModel. * @@ -123,64 +196,6 @@ class BrowseController extends AbstractBase $view->currentAction = $currentAction; } - // Initialize the array of top-level browse options. - $browseOptions = []; - - // First option: tags -- is it enabled in config.ini? If no setting is - // found, assume it is active. Note that this setting is disabled if tags - // are universally turned off. - if ((!isset($this->config->Browse->tag) || $this->config->Browse->tag) - && $this->tagsEnabled() - ) { - $browseOptions[] = $this->buildBrowseOption('Tag', 'Tag'); - $view->tagEnabled = true; - } - - // Read configuration settings for LC / Dewey call number display; default - // to LC only if no settings exist in config.ini. - if (!isset($this->config->Browse->dewey) - && !isset($this->config->Browse->lcc) - ) { - $lcc = true; - $dewey = false; - } else { - $lcc = (isset($this->config->Browse->lcc) - && $this->config->Browse->lcc); - $dewey = (isset($this->config->Browse->dewey) - && $this->config->Browse->dewey); - } - - // Add the call number options as needed -- note that if both options exist, - // we need to use special text to disambiguate them. - if ($dewey) { - $browseOptions[] = $this->buildBrowseOption( - 'Dewey', ($lcc ? 'browse_dewey' : 'Call Number') - ); - $view->deweyEnabled = true; - } - if ($lcc) { - $browseOptions[] = $this->buildBrowseOption( - 'LCC', ($dewey ? 'browse_lcc' : 'Call Number') - ); - $view->lccEnabled = true; - } - - // Loop through remaining browse options. All may be individually disabled - // in config.ini, but if no settings are found, they are assumed to be on. - $remainingOptions = [ - 'Author', 'Topic', 'Genre', 'Region', 'Era' - ]; - foreach ($remainingOptions as $current) { - $option = strtolower($current); - if (!isset($this->config->Browse->$option) - || $this->config->Browse->$option == true - ) { - $browseOptions[] = $this->buildBrowseOption($current, $current); - $option .= 'Enabled'; - $view->$option = true; - } - } - // CARRY if ($findby = $this->params()->fromQuery('findby')) { $view->findby = $findby; @@ -191,7 +206,7 @@ class BrowseController extends AbstractBase if ($category = $this->params()->fromQuery('category')) { $view->category = $category; } - $view->browseOptions = $browseOptions; + $view->browseOptions = $this->buildBrowseOptions(); return $view; }