Skip to content
Snippets Groups Projects
Commit 721211df authored by Demian Katz's avatar Demian Katz
Browse files

Made combined search handler drop-down smarter.

- Better default selection on home page
- Include options for non-configured handlers when needed in context
parent f916dba5
No related merge requests found
...@@ -115,8 +115,8 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -115,8 +115,8 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
* drop-down or hidden field. Returns an array of arrays with 'value', 'label', * drop-down or hidden field. Returns an array of arrays with 'value', 'label',
* 'indent' and 'selected' keys. * 'indent' and 'selected' keys.
* *
* @param string $activeSearchClass Active search class ID * @param string $activeSearchClass Active search class ID
* @param string $activeHandler Active search handler * @param string $activeHandler Active search handler
* *
* @return array * @return array
*/ */
...@@ -130,8 +130,8 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -130,8 +130,8 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
/** /**
* Support method for getHandlers() -- load basic settings. * Support method for getHandlers() -- load basic settings.
* *
* @param string $activeSearchClass Active search class ID * @param string $activeSearchClass Active search class ID
* @param string $activeHandler Active search handler * @param string $activeHandler Active search handler
* *
* @return array * @return array
*/ */
...@@ -149,14 +149,13 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -149,14 +149,13 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
} }
/** /**
* Support method for getHandlers() -- load combined settings. * Support method for getCombinedHandlers() -- retrieve/validate configuration.
* *
* @param string $activeSearchClass Active search class ID * @param string $activeSearchClass Active search class ID
* @param string $activeHandler Active search handler
* *
* @return array * @return array
*/ */
protected function getCombinedHandlers($activeSearchClass, $activeHandler) protected function getCombinedHandlerConfig($activeSearchClass)
{ {
// Load and validate configuration: // Load and validate configuration:
$settings = isset($this->config['CombinedHandlers']) $settings = isset($this->config['CombinedHandlers'])
...@@ -171,8 +170,33 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -171,8 +170,33 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
throw new \Exception('CombinedHandlers configuration incomplete.'); throw new \Exception('CombinedHandlers configuration incomplete.');
} }
// Add configuration for the current search class if it is not already
// present:
if (!in_array($activeSearchClass, $settings['target'])) {
$settings['type'][] = 'VuFind';
$settings['target'][] = $activeSearchClass;
$settings['label'][] = $activeSearchClass;
}
return $settings;
}
/**
* Support method for getHandlers() -- load combined settings.
*
* @param string $activeSearchClass Active search class ID
* @param string $activeHandler Active search handler
*
* @return array
*/
protected function getCombinedHandlers($activeSearchClass, $activeHandler)
{
// Build settings: // Build settings:
$handlers = array(); $handlers = array();
$selectedFound = false;
$backupSelectedIndex = false;
$settings = $this->getCombinedHandlerConfig($activeSearchClass);
$typeCount = count($settings['type']);
for ($i = 0; $i < $typeCount; $i++) { for ($i = 0; $i < $typeCount; $i++) {
$type = $settings['type'][$i]; $type = $settings['type'][$i];
$target = $settings['target'][$i]; $target = $settings['target'][$i];
...@@ -183,12 +207,20 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -183,12 +207,20 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
$j = 0; $j = 0;
foreach ($options->getBasicHandlers() as $searchVal => $searchDesc) { foreach ($options->getBasicHandlers() as $searchVal => $searchDesc) {
$j++; $j++;
$selected = $target == $activeSearchClass
&& $activeHandler == $searchVal;
if ($selected) {
$selectedFound = true;
} else if ($backupSelectedIndex === false
&& $target == $activeSearchClass
) {
$backupSelectedIndex = count($handlers);
}
$handlers[] = array( $handlers[] = array(
'value' => $type . ':' . $target . '|' . $searchVal, 'value' => $type . ':' . $target . '|' . $searchVal,
'label' => $j == 1 ? $label : $searchDesc, 'label' => $j == 1 ? $label : $searchDesc,
'indent' => $j == 1 ? false : true, 'indent' => $j == 1 ? false : true,
'selected' => $target == $activeSearchClass 'selected' => $selected
&& $activeHandler == $searchVal
); );
} }
} else if ($type == 'External') { } else if ($type == 'External') {
...@@ -198,6 +230,12 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper ...@@ -198,6 +230,12 @@ class SearchBox extends \Zend\View\Helper\AbstractHelper
); );
} }
} }
// If we didn't find an exact match for a selected index, use a fuzzy
// match:
if (!$selectedFound && $backupSelectedIndex !== false) {
$handlers[$backupSelectedIndex]['selected'] = true;
}
return $handlers; return $handlers;
} }
} }
\ No newline at end of file
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