Skip to content
Snippets Groups Projects
Commit c7db1a4d authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Allow browse options to be re-ordered through configuration. (#1629)

- Resolves VUFIND-1397
- Removes unused {$option}Enabled view properties
parent cf7dc495
Branches
Tags
No related merge requests found
...@@ -1489,6 +1489,10 @@ rtl_langs = "ar,he" ...@@ -1489,6 +1489,10 @@ rtl_langs = "ar,he"
; have a large index! ; have a large index!
[Browse] [Browse]
result_limit = 100 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 tag = true ; allow browsing of Tags
dewey = false ; allow browsing of Dewey Decimal call numbers dewey = false ; allow browsing of Dewey Decimal call numbers
lcc = true ; allow browsing of LC call numbers lcc = true ; allow browsing of LC call numbers
...@@ -1497,6 +1501,7 @@ topic = true ; allow browsing of subject headings ...@@ -1497,6 +1501,7 @@ topic = true ; allow browsing of subject headings
genre = true ; allow browsing of genre subdivisions genre = true ; allow browsing of genre subdivisions
region = true ; allow browsing of region subdivisions region = true ; allow browsing of region subdivisions
era = true ; allow browsing of era subdivisions era = true ; allow browsing of era subdivisions
; You can use this setting to change the default alphabet provided for browsing: ; You can use this setting to change the default alphabet provided for browsing:
;alphabet_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;alphabet_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
; Uncomment to sort lists alphabetically (instead of by popularity); note that ; Uncomment to sort lists alphabetically (instead of by popularity); note that
......
...@@ -106,6 +106,79 @@ class BrowseController extends AbstractBase ...@@ -106,6 +106,79 @@ class BrowseController extends AbstractBase
return $this->currentAction; 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. * Create a new ViewModel.
* *
...@@ -123,64 +196,6 @@ class BrowseController extends AbstractBase ...@@ -123,64 +196,6 @@ class BrowseController extends AbstractBase
$view->currentAction = $currentAction; $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 // CARRY
if ($findby = $this->params()->fromQuery('findby')) { if ($findby = $this->params()->fromQuery('findby')) {
$view->findby = $findby; $view->findby = $findby;
...@@ -191,7 +206,7 @@ class BrowseController extends AbstractBase ...@@ -191,7 +206,7 @@ class BrowseController extends AbstractBase
if ($category = $this->params()->fromQuery('category')) { if ($category = $this->params()->fromQuery('category')) {
$view->category = $category; $view->category = $category;
} }
$view->browseOptions = $browseOptions; $view->browseOptions = $this->buildBrowseOptions();
return $view; return $view;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment