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

Refactored redundant code.

parent 5f3b128f
No related merge requests found
...@@ -290,6 +290,37 @@ class Options extends \VuFind\Search\Base\Options ...@@ -290,6 +290,37 @@ class Options extends \VuFind\Search\Base\Options
} }
} }
/**
* Apply user-requested "common" settings.
*
* @param \Zend\Config\Config $searchSettings Configuration
* @param string $setting Name of common setting
* @param string $list Name of property containing valid
* values
* @param string $target Name of property to populate
*
* @return void
*/
protected function setCommonSettings($searchSettings, $setting, $list, $target)
{
if (isset($searchSettings->General->$setting)) {
$userValues = explode(',', $searchSettings->General->$setting);
if (!empty($userValues) && isset($this->$list) && !empty($this->$list)) {
// Reference to property containing API-provided whitelist of values
$listRef = & $this->$list;
// Reference to property containing final common settings
$targetRef = & $this->$target;
foreach ($userValues as $current) {
// Only add values that are valid according to the API's list
if (isset($listRef[$current])) {
$targetRef[] = $current;
}
}
}
}
}
/** /**
* Load options from the configuration file. These will override the defaults set * Load options from the configuration file. These will override the defaults set
* from the values in the Info method. (If the values set in the config files in * from the values in the Info method. (If the values set in the config files in
...@@ -366,43 +397,14 @@ class Options extends \VuFind\Search\Base\Options ...@@ -366,43 +397,14 @@ class Options extends \VuFind\Search\Base\Options
= $searchSettings->Advanced_Facet_Settings->special_facets; = $searchSettings->Advanced_Facet_Settings->special_facets;
} }
// Set common limiters and expanders.
//Only the common limiters that are valid limiters for this profile // Only the values that are valid for this profile will be used.
//will be used $this->setCommonSettings(
if (isset($searchSettings->General->common_limiters)) { $searchSettings, 'common_limiters', 'limiterOptions', 'commonLimiters'
$commonLimiters = $searchSettings->General->common_limiters; );
if (isset($commonLimiters)) { $this->setCommonSettings(
$cLimiters = explode(',', $commonLimiters); $searchSettings, 'common_expanders', 'expanderOptions', 'commonExpanders'
);
if (!empty($cLimiters) && isset($this->limiterOptions)
&& !empty($this->limiterOptions)
) {
foreach ($cLimiters as $cLimiter) {
if (isset($this->limiterOptions[$cLimiter])) {
$this->commonLimiters[] = $cLimiter;
}
}
}
}
}
//Only the common expanders that are valid expanders for this profile
//will be used
if (isset($searchSettings->General->common_expanders)) {
$commonExpanders= $searchSettings->General->common_expanders;
if (isset($commonExpanders)) {
$cExpanders = explode(',', $commonExpanders);
if (!empty($cExpanders) && isset($this->expanderOptions)
&& !empty($this->expanderOptions)
) {
foreach ($cExpanders as $cExpander) {
if (isset($this->expanderOptions[$cExpander])) {
$this->commonExpanders[] = $cExpander;
}
}
}
}
}
} }
/** /**
......
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