Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions module/VuFind/src/VuFind/Recommend/AbstractFacets.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace VuFind\Recommend;

use VuFind\Config\Config;

use function in_array;

/**
Expand Down Expand Up @@ -127,29 +125,29 @@ public function getResults()
/**
* Read boolean (OR/NOT) settings from the provided configuration.
*
* @param Config $config Configuration to read
* @param array $config Configuration to read
Comment thread
rtloftus marked this conversation as resolved.
* @param array $allFacets All facets (to use when config = *)
* @param string $section Configuration section containing settings
*
* @return void
*/
protected function loadBooleanConfigs(
Config $config,
array $config,
$allFacets,
$section = 'Results_Settings'
) {
// Which facets are excludable?
if (isset($config->$section->exclude)) {
$this->excludableFacets = ($config->$section->exclude === '*')
if (isset($config[$section]['exclude'])) {
$this->excludableFacets = ($config[$section]['exclude'] === '*')
? $allFacets
: array_map('trim', explode(',', $config->$section->exclude));
: array_map('trim', explode(',', $config[$section]['exclude']));
}

// Which facets are ORed?
if (isset($config->$section->orFacets)) {
$this->orFacets = ($config->$section->orFacets === '*')
if (isset($config[$section]['orFacets'])) {
$this->orFacets = ($config[$section]['orFacets'] === '*')
? $allFacets
: array_map('trim', explode(',', $config->$section->orFacets));
: array_map('trim', explode(',', $config[$section]['orFacets']));
}
}
}
54 changes: 23 additions & 31 deletions module/VuFind/src/VuFind/Recommend/SideFacets.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,27 @@ public function setConfig($settings)
$showDynamicCheckboxFacets = $settings[3] ?? true;

// Load the desired facet information...
$config = $this->configManager->getConfigObject($iniName);
$config = $this->configManager->getConfigArray($iniName);

// All standard facets to display:
$this->mainFacets = isset($config->$mainSection) ?
$config->$mainSection->toArray() : [];
$this->mainFacets = $config[$mainSection] ?? [];

// Load boolean configurations:
$this->loadBooleanConfigs($config, array_keys($this->mainFacets));

// Get a list of fields that should be displayed as ranges rather than
// standard facet lists.
if (isset($config->SpecialFacets->dateRange)) {
$this->dateFacets = $config->SpecialFacets->dateRange->toArray();
if (isset($config['SpecialFacets']['dateRange'])) {
$this->dateFacets = $config['SpecialFacets']['dateRange'];
}
if (isset($config->SpecialFacets->fullDateRange)) {
$this->fullDateFacets = $config->SpecialFacets->fullDateRange->toArray();
if (isset($config['SpecialFacets']['fullDateRange'])) {
$this->fullDateFacets = $config['SpecialFacets']['fullDateRange'];
}
if (isset($config->SpecialFacets->genericRange)) {
$this->genericRangeFacets
= $config->SpecialFacets->genericRange->toArray();
if (isset($config['SpecialFacets']['genericRange'])) {
$this->genericRangeFacets = $config['SpecialFacets']['genericRange'];
}
if (isset($config->SpecialFacets->numericRange)) {
$this->numericRangeFacets
= $config->SpecialFacets->numericRange->toArray();
if (isset($config['SpecialFacets']['numericRange'])) {
$this->numericRangeFacets = $config['SpecialFacets']['numericRange'];
}

// Checkbox facets:
Expand All @@ -208,9 +205,8 @@ public function setConfig($settings)
$checkboxSection = substr($checkboxSection, 1);
$flipCheckboxes = true;
}
$this->checkboxFacets
= ($checkboxSection && isset($config->$checkboxSection))
? $config->$checkboxSection->toArray() : [];
$this->checkboxFacets = ($checkboxSection && isset($config[$checkboxSection]))
? $config[$checkboxSection] : [];
if ($flipCheckboxes) {
$this->checkboxFacets = array_flip($this->checkboxFacets);
}
Expand All @@ -220,33 +216,29 @@ public function setConfig($settings)
) {
$this->showDynamicCheckboxFacets = false;
}
$this->showCheckboxFacetCounts = (bool)($config->Results_Settings->checkboxFacetCounts ?? false);
$this->showCheckboxFacetCounts = (bool)($config['Results_Settings']['checkboxFacetCounts'] ?? false);

// Show more settings:
if (isset($config->Results_Settings->showMore)) {
$this->showMoreSettings
= $config->Results_Settings->showMore->toArray();
if (isset($config['Results_Settings']['showMore'])) {
$this->showMoreSettings = $config['Results_Settings']['showMore'];
}
if (isset($config->Results_Settings->showMoreInLightbox)) {
$this->showInLightboxSettings
= $config->Results_Settings->showMoreInLightbox->toArray();
if (isset($config['Results_Settings']['showMoreInLightbox'])) {
$this->showInLightboxSettings = $config['Results_Settings']['showMoreInLightbox'];
}

// Collapsed facets:
if (isset($config->Results_Settings->collapsedFacets)) {
$this->collapsedFacets = $config->Results_Settings->collapsedFacets;
if (isset($config['Results_Settings']['collapsedFacets'])) {
$this->collapsedFacets = $config['Results_Settings']['collapsedFacets'];
}

// Hierarchical facets:
if (isset($config->SpecialFacets->hierarchical)) {
$this->hierarchicalFacets
= $config->SpecialFacets->hierarchical->toArray();
if (isset($config['SpecialFacets']['hierarchical'])) {
$this->hierarchicalFacets = $config['SpecialFacets']['hierarchical'];
}

// Hierarchical facet sort options:
if (isset($config->SpecialFacets->hierarchicalFacetSortOptions)) {
$this->hierarchicalFacetSortOptions
= $config->SpecialFacets->hierarchicalFacetSortOptions->toArray();
if (isset($config['SpecialFacets']['hierarchicalFacetSortOptions'])) {
$this->hierarchicalFacetSortOptions = $config['SpecialFacets']['hierarchicalFacetSortOptions'];
}
}

Expand Down
7 changes: 3 additions & 4 deletions module/VuFind/src/VuFind/Recommend/TopFacets.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public function setConfig($settings)
$iniName = $settings[1] ?? 'facets';

// Load the desired facet information:
$config = $this->configManager->getConfigObject($iniName);
$this->facets = isset($config->$mainSection)
? $config->$mainSection->toArray() : [];
$config = $this->configManager->getConfigArray($iniName);
$this->facets = $config[$mainSection] ?? [];

// Load other relevant settings:
$this->baseSettings = [
'rows' => $config->Results_Settings->top_rows,
'rows' => $config['Results_Settings']['top_rows'],
Comment thread
demiankatz marked this conversation as resolved.
Outdated
];

// Load boolean configurations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testHierarchicalGetters(): void
],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$sf = $this->getSideFacets($configManager);
$this->assertEquals(['format'], $sf->getHierarchicalFacets());
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testFacetInit(): void
],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$results = $this->getMockResults();
$params = $results->getParams();
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testGetFacetOperator(): void
],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$sf = $this->getSideFacets($configManager);
$this->assertEquals('OR', $sf->getFacetOperator('format'));
Expand All @@ -168,7 +168,7 @@ public function testExcludeAllowed(): void
],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$sf = $this->getSideFacets($configManager);
$this->assertTrue($sf->excludeAllowed('format'));
Expand All @@ -192,7 +192,7 @@ public function testGetAllRangeFacets(): void
],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$filters = [
'date' => ['[1900 TO 1905]'],
Expand Down Expand Up @@ -238,7 +238,7 @@ public function testGetCollapsedFacetsDelimitedList(): void
'Results_Settings' => ['collapsedFacets' => ' foo, bar,baz '],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$sf = $this->getSideFacets($configManager);
$this->assertEquals(['foo', 'bar', 'baz'], $sf->getCollapsedFacets());
Expand All @@ -260,7 +260,7 @@ public function testGetCollapsedFacetsWildcard(): void
'Results_Settings' => ['collapsedFacets' => '*'],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$results = $this->getMockResults();
$sf = $this->getSideFacets($configManager, $results);
Expand Down Expand Up @@ -298,7 +298,7 @@ public function testGetCheckboxFacetSetReturnsValueWhenAppropriate(): void
'Checkboxes' => ['foo' => 'bar'],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$checkboxData = [
[
Expand Down Expand Up @@ -331,7 +331,7 @@ public function testDynamicCheckboxesCanBeDisabled(): void
'Checkboxes' => ['foo' => 'bar'],
],
],
getConfigObjectExpect: $this->once()
getConfigArrayExpect: $this->once()
);
$checkboxData = [
[
Expand Down