Skip to content

Commit

Permalink
Configurable views for EDS (#4199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoWagen authored Jan 27, 2025
1 parent 1b3a9fd commit 6311aa5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 25 deletions.
16 changes: 15 additions & 1 deletion config/vufind/EDS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ common_limiters = FC,FT,RV
; values. Order of values here controls display order in the form.
;advanced_limiters = RV,FC,FT
common_expanders = fulltext
default_view = brief
; This setting controls the default view for search results; the selected option
; should be one of the options present in the [Views] section below.
default_view = list_brief
; If a warning should be shown on searches and records when the user only has a restricted view.
show_restricted_view_warning = false

Expand Down Expand Up @@ -269,6 +271,18 @@ SU = Subject
; through the current result set from within the record view.
next_prev_navigation = false

; This section defines the view options available on standard search results.
; If only one view is required, set default_view under [General] above, and comment
; this section out.
; The key takes the form vufindSetting_ebscoSetting -- the first part of the
; underscore-delimited string is the view name used by VuFind (e.g. list or grid).
; However, for EDS only list is suggested to be used. The second part is the format
; requested from the EDS API (e.g. title, brief or detailed).
[Views]
list_title = "Title View"
list_brief = "Brief View"
list_detailed = "Detailed View"

; This section represents the EBSCO EDS API Account credentials.
; If using IP Authentication, then the user_name and password should remain blank
; and ip_auth should be set to true.
Expand Down
27 changes: 27 additions & 0 deletions module/VuFind/src/VuFind/Config/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function run()
$this->upgradeSearches();
$this->upgradeSitemap();
$this->upgradeSms();
$this->upgradeEDS();
$this->upgradeSummon();
$this->upgradePrimo();

Expand Down Expand Up @@ -1039,6 +1040,32 @@ protected function upgradeReserves()
$this->saveModifiedConfig('reserves.ini');
}

/**
* Upgrade EDS.ini.
*
* @throws FileAccessException
* @return void
*/
protected function upgradeEDS()
{
// we want to retain the old installation's search and facet settings
// exactly as-is
$groups = [
'Facets', 'FacetsTop', 'Basic_Searches', 'Advanced_Searches', 'Sorting',
];
$this->applyOldSettings('EDS.ini', $groups);

// Fix default view settings in case they use the old style:
$newConfig = & $this->newConfigs['EDS.ini']['General'];

if (!str_contains($newConfig['default_view'], '_')) {
$newConfig['default_view'] = 'list_' . $newConfig['default_view'];
}

// save the file
$this->saveModifiedConfig('EDS.ini');
}

/**
* Upgrade Summon.ini.
*
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Search/EDS/AbstractEDSParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function filterRequiresFacetOperator($field)
*/
public function getView()
{
$viewArr = explode('|', $this->view ?? '');
$viewArr = explode('_', $this->view ?? '');
return $viewArr[0];
}

Expand Down
43 changes: 26 additions & 17 deletions module/VuFind/src/VuFind/Search/EDS/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
class Options extends \VuFind\Search\Base\Options
{
use \VuFind\Config\Feature\ExplodeSettingTrait;
use \VuFind\Search\Options\ViewOptionsTrait;

/**
* Default limit option
Expand Down Expand Up @@ -168,13 +169,6 @@ public function __construct(
$this->searchIni = $this->facetsIni = 'EDS';
$this->searchSettings = $configLoader->get($this->searchIni);
parent::__construct($configLoader);
// 2015-06-30 RF - Changed to unlimited
//$this->resultLimit = 100;
$this->viewOptions = [
'list|title' => 'Title View',
'list|brief' => 'Brief View',
'list|detailed' => 'Detailed View',
];
// If we get the API info as a callback, defer until it's actually needed to
// avoid calling the API:
if (is_callable($apiInfo)) {
Expand Down Expand Up @@ -312,14 +306,13 @@ public function getDefaultMode()
}

/**
* Return the view associated with this configuration
* Return the view type to request from the EDS API.
*
* @return string
*/
public function getEdsView()
{
$viewArr = explode('|', $this->getApiProperty('defaultView'));
return (1 < count($viewArr)) ? $viewArr[1] : $this->defaultView;
return $this->getDefaultViewPart(1);
}

/**
Expand Down Expand Up @@ -492,10 +485,7 @@ protected function setOptionsFromConfig()
}

// View preferences
if (isset($this->searchSettings->General->default_view)) {
$this->defaultView
= 'list|' . $this->searchSettings->General->default_view;
}
$this->initViewOptions($this->searchSettings);

// Load list view for result (controls AJAX embedding vs. linking)
if (isset($this->searchSettings->List->view)) {
Expand Down Expand Up @@ -724,7 +714,7 @@ protected function populateViewSettings()
$this->defaultLimit ??= $settings['ResultsPerPage'] ?? 20;

// default view
$this->defaultView ??= 'list|' . ($settings['ResultListView'] ?? 'brief');
$this->defaultView ??= 'list_' . ($settings['ResultListView'] ?? 'brief');
}

/**
Expand Down Expand Up @@ -796,8 +786,7 @@ public function getSearchScreenExpanders()
*/
public function getDefaultView()
{
$viewArr = explode('|', $this->getApiProperty('defaultView'));
return $viewArr[0];
return $this->getDefaultViewPart(0, 'list');
}

/**
Expand Down Expand Up @@ -828,4 +817,24 @@ public function getDefaultFilters()
}
return $this->defaultFilters;
}

/**
* Extract a component from the defaultView API property.
*
* The defaultView API property takes the form vufindSetting_ebscoSetting -- the first component
* of the underscore-delimited string is the view name used by VuFind (e.g. list or grid).
* However, for EDS only list is suggested to be used. The second component is the format
* requested from the EDS API (e.g. title, brief or detailed).
*
* @param int $index Index of part to extract from the property
* @param ?string $default Default to use as a fallback if the property does not contain delimited values
*
* @return string
*/
protected function getDefaultViewPart(int $index, ?string $default = null): string
{
$apiDefaultView = $this->getApiProperty('defaultView');
$viewArr = explode('_', $apiDefaultView);
return (count($viewArr) > 1) ? $viewArr[$index] : ($default ?? $apiDefaultView);
}
}
4 changes: 2 additions & 2 deletions module/VuFind/src/VuFind/Search/EDS/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function getBackendParameters()
*/
public function getEdsView()
{
$viewArr = explode('|', $this->view ?? '');
$viewArr = explode('_', $this->view ?? '');
return (1 < count($viewArr)) ? $viewArr[1] : $this->options->getEdsView();
}

Expand Down Expand Up @@ -310,7 +310,7 @@ public function getViewList()
foreach ($this->getOptions()->getViewOptions() as $key => $value) {
$list[$key] = [
'desc' => $value,
'selected' => ($key == $this->getView() . '|' . $this->getEdsView()),
'selected' => ($key == $this->getView() . '_' . $this->getEdsView()),
];
}
return $list;
Expand Down
10 changes: 6 additions & 4 deletions module/VuFind/src/VuFind/Search/Options/ViewOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public function initViewOptions(?Config $searchSettings)
$this->defaultView = $searchSettings->General->default_view;
}
// Load view preferences (or defaults if none in .ini file):
if (isset($searchSettings->Views)) {
foreach ($searchSettings->Views as $key => $value) {
$this->viewOptions[$key] = $value;
}
$viewOptions = [];
foreach ($searchSettings->Views ?? [] as $key => $value) {
$viewOptions[$key] = $value;
}
if (!empty($viewOptions)) {
$this->viewOptions = $viewOptions;
} elseif (isset($searchSettings->General->default_view)) {
$this->viewOptions = [$this->defaultView => $this->defaultView];
} else {
Expand Down
5 changes: 5 additions & 0 deletions module/VuFind/tests/fixtures/configs/eds/EDS.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Facets]
foo = bar

[General]
default_view = test
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,27 @@ public function testCommentExtraction(): void
);
}

/**
* Test EDS upgrade.
*
* @return void
*/
public function testEDSUpgrade(): void
{
$upgrader = $this->getUpgrader('eds');
$upgrader->run();
$this->assertEquals([], $upgrader->getWarnings());
$results = $upgrader->getNewConfigs();
$this->assertEquals(
['foo' => 'bar'],
$results['EDS.ini']['Facets']
);
$this->assertEquals(
'list_test',
$results['EDS.ini']['General']['default_view']
);
}

/**
* Test Primo upgrade.
*
Expand Down

0 comments on commit 6311aa5

Please sign in to comment.