diff --git a/config/vufind/EDS.ini b/config/vufind/EDS.ini index bfd8f9bbad58172e6bd61ace5df27c026af058b4..5eab9bf26bd844b6068efe32f4d796f141dde1ec 100644 --- a/config/vufind/EDS.ini +++ b/config/vufind/EDS.ini @@ -267,3 +267,24 @@ auto_submit = true ;AllFields = Eds:rawqueries ;TI = Eds:holdings AU = None + +; This section can be used to filter out unwanted items from display in any context. +[ItemGlobalFilter] +; This repeatable setting can be used to filter out values based on their labels: +;excludeLabel[] = 'Availability' +; This repeatable setting can be used to filter out values using group codes: +;excludeGroup[] = 'URL' + +; Similar to [ItemGlobalFilter] but applied only for record view. +[ItemCoreFilter] +; This repeatable setting can be used to filter out values based on their labels: +;excludeLabel[] = 'Availability' +; This repeatable setting can be used to filter out values using group codes: +;excludeGroup[] = 'URL' + +; Similar to [ItemGlobalFilter] but applied only for search result view. +[ItemResultListFilter] +; This repeatable setting can be used to filter out values based on their labels: +;excludeLabel[] = 'Availability' +; This repeatable setting can be used to filter out values using group codes: +;excludeGroup[] = 'URL' diff --git a/module/VuFind/src/VuFind/RecordDriver/EDS.php b/module/VuFind/src/VuFind/RecordDriver/EDS.php index 5f4c020a96136aa1ae45ce181c1e750837a5ca93..22218822caad91eb4fa5237ab382f645021a0847 100644 --- a/module/VuFind/src/VuFind/RecordDriver/EDS.php +++ b/module/VuFind/src/VuFind/RecordDriver/EDS.php @@ -193,22 +193,63 @@ class EDS extends DefaultRecord && ('1' == $this->fields['FullText']['Text']['Availability']); } + /** + * Support method for getItems, used to apply filters. + * + * @param array $item Item to check + * @param string $context The context in which items are being retrieved + * (used for context-sensitive filtering) + * + * @return bool + */ + protected function itemIsExcluded($item, $context) + { + // Create a list of config sections to check, based on context: + $sections = ['ItemGlobalFilter']; + switch ($context) { + case 'result-list': + $sections[] = 'ItemResultListFilter'; + break; + case 'core': + $sections[] = 'ItemCoreFilter'; + break; + } + // Check to see if anything is filtered: + foreach ($sections as $section) { + $currentConfig = isset($this->recordConfig->$section) + ? $this->recordConfig->$section->toArray() : []; + $badLabels = (array)($currentConfig['excludeLabel'] ?? []); + $badGroups = (array)($currentConfig['excludeGroup'] ?? []); + if (in_array($item['Label'], $badLabels) + || in_array($item['Group'], $badGroups) + ) { + return true; + } + } + // If we got this far, no filter was applied: + return false; + } + /** * Get the items of the record. * + * @param string $context The context in which items are being retrieved + * (used for context-sensitive filtering) + * * @return array */ - public function getItems() + public function getItems($context = null) { $items = []; - if (isset($this->fields['Items']) && !empty($this->fields['Items'])) { - foreach ($this->fields['Items'] as $item) { - $items[] = [ - 'Label' => $item['Label'] ?? '', - 'Group' => $item['Group'] ?? '', - 'Data' => isset($item['Data']) - ? $this->toHTML($item['Data'], $item['Group']) : '' - ]; + foreach ($this->fields['Items'] ?? [] as $item) { + $nextItem = [ + 'Label' => $item['Label'] ?? '', + 'Group' => $item['Group'] ?? '', + 'Data' => isset($item['Data']) + ? $this->toHTML($item['Data'], $item['Group']) : '' + ]; + if (!$this->itemIsExcluded($nextItem, $context)) { + $items[] = $nextItem; } } return $items; diff --git a/themes/bootstrap3/templates/RecordDriver/EDS/core.phtml b/themes/bootstrap3/templates/RecordDriver/EDS/core.phtml index 7e03a4e0f9538fabe02259497b2d5721bf859ee1..2149bdb45bdf8df414ed7021a0face096d074522 100644 --- a/themes/bootstrap3/templates/RecordDriver/EDS/core.phtml +++ b/themes/bootstrap3/templates/RecordDriver/EDS/core.phtml @@ -1,6 +1,6 @@ <?php $this->headLink()->appendStylesheet('EDS.css'); ?> <?php - $items = $this->driver->getItems(); + $items = $this->driver->getItems('core'); $dbLabel = $this->driver->getDbLabel(); $thumb = $this->driver->getThumbnail('medium'); $pubType = $this->driver->getPubType(); diff --git a/themes/bootstrap3/templates/RecordDriver/EDS/result-list.phtml b/themes/bootstrap3/templates/RecordDriver/EDS/result-list.phtml index dca553c6de9b4c91415781c4712824a5de3b7ab3..f6cacbc0f3ab05477fd20c989abd14a2cbcca108 100644 --- a/themes/bootstrap3/templates/RecordDriver/EDS/result-list.phtml +++ b/themes/bootstrap3/templates/RecordDriver/EDS/result-list.phtml @@ -28,7 +28,7 @@ <?php endif; ?> <div class="media-body"> <div class="result-body"> - <?php $items = $this->driver->getItems(); + <?php $items = $this->driver->getItems('result-list'); if (isset($items) && !empty($items)): foreach ($items as $item): if (!empty($item)): ?>