Skip to content

Commit adbfff8

Browse files
committed
Add new method getCoverUrl to record drivers
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 1575d4a commit adbfff8

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

module/VuFind/src/VuFind/Content/Covers/RecordData.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ public function getUrl($key, $size, $ids)
6969
$recordId = $ids['recordid'];
7070
$source = $ids['source'] ?? DEFAULT_SEARCH_BACKEND;
7171
$driver = $this->recordLoader->load($recordId, $source);
72-
$marc = $driver->getMarcReader();
73-
$fields856 = $marc->getFields('856');
74-
foreach ($fields856 as $field) {
75-
$description = $marc->getSubfield($field, '3');
76-
if (stripos($description, 'cover') !== false) {
77-
$url = $marc->getSubfield($field, 'u');
78-
return $url;
79-
}
80-
}
81-
return false;
72+
return $driver->getCoverUrl();
8273
}
8374
}

module/VuFind/src/VuFind/RecordDriver/DefaultRecord.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,18 @@ public function getCorporateAuthorsRoles()
433433
return (array)($this->fields['author_corporate_role'] ?? []);
434434
}
435435

436+
/**
437+
* Get URL of cover image.
438+
* This method should be overridden by record driver implementations which
439+
* can provide information about cover images.
440+
*
441+
* @return string|bool URL of the image, or false if no valid image is found
442+
*/
443+
public function getCoverUrl()
444+
{
445+
return false;
446+
}
447+
436448
/**
437449
* Get the date coverage for a record which spans a period of time (i.e. a
438450
* journal). Use getPublicationDates for publication dates of particular

module/VuFind/src/VuFind/RecordDriver/Feature/MarcReaderTrait.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ public function getMarcReader()
103103
return $this->lazyMarcReader;
104104
}
105105

106+
/**
107+
* Get URL of cover image from MARC field.
108+
*
109+
* @return string|bool URL of the image, or false if no valid image is found
110+
*/
111+
public function getCoverUrl()
112+
{
113+
$marc = $this->getMarcReader();
114+
$fields856 = $marc->getFields('856');
115+
foreach ($fields856 as $field) {
116+
$description = $marc->getSubfield($field, '3');
117+
if (stripos($description, 'cover') !== false) {
118+
$url = $marc->getSubfield($field, 'u');
119+
return $url;
120+
}
121+
}
122+
return false;
123+
}
124+
106125
/**
107126
* Return an array of all values extracted from the specified field/subfield
108127
* combination. If multiple subfields are specified and $concat is true, they

0 commit comments

Comments
 (0)