Skip to content

Commit

Permalink
feat: check for libKey setting
Browse files Browse the repository at this point in the history
Only ever use the LibKey integration if a LibKey
setting is associated with the active library.

This aims to ensure that the LibKey integration
code only runs if LibKey has been set up for the
relevant library.
  • Loading branch information
Chloe070196 committed Dec 3, 2024
1 parent df58ae1 commit 27ebf39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
25 changes: 10 additions & 15 deletions code/web/RecordDrivers/MarcRecordDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1314,14 +1314,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
$i = 0;
if (count($relatedUrls) > 1) {
//We will show a popup to let people choose the URL they want
foreach($relatedUrls as $relatedUrl) {
$libKeyLink = $this->getLibKeyUrl($relatedUrl['url']);
if (!empty($libKeyLink)) {
$libKeyRelatedUrl = $relatedUrl;
$libKeyrelatedUrl['url'] = $libKeyLink;
$relatedUrls[] = $libKeyRelatedUrl;
}
}

$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
Expand All @@ -1335,17 +1328,17 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
'id' => "accessOnline_{$this->getId()}",
'target' => '_blank',
];
} elseif (count($relatedUrls) == 1) {
} elseif (count($relatedUrls) == 1) {

$libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']);
if (!empty($libKeyLink)) {
if (Library::getActiveLibrary()->libKeySettingId != -1) {
$libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']);
$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
]);
$actions[] = [
'title' => $title,
'url' => $libKeyLink,
'url' => $libKeyLink ? $libKeyLink : '',
'requireLogin' => false,
'type' => 'access_online',
'id' => "accessOnline_{$this->getId()}",
Expand Down Expand Up @@ -1690,9 +1683,11 @@ public function getMoreDetailsOptions() {
$interface->assign('periodicalIssues', $issues);
}
$links = $this->getLinks();
$libKeyLink = $this->getLibKeyUrl($links[0]['url']);
if (!empty($libKeyLink)) {
$links[] = ['title' => $libKeyLink, 'url' => $libKeyLink];
if (Library::getActiveLibrary()->libKeySettingId != -1) {
$libKeyLink = $this->getLibKeyUrl($links[0]['url']);
if (!empty($libKeyLink)) {
$links[] = ['title' => $libKeyLink, 'url' => $libKeyLink];
}
}
$interface->assign('links', $links);
$interface->assign('show856LinksAsTab', $library->getGroupedWorkDisplaySettings()->show856LinksAsTab);
Expand Down
21 changes: 14 additions & 7 deletions code/web/services/Record/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -1996,17 +1996,24 @@ function viewItem(): array {
if ($item->itemId == $itemId) {
$relatedUrls = $item->getRelatedUrls();
foreach ($relatedUrls as $relatedUrl) {
$libKeyLink = $this->getLibKeyUrl($relatedUrl['url']);
if (!empty($libKeyLink)) {
return [
'success' => true,
'url' => $libKeyLink
];
if (Library::getActiveLibrary()->libKeySettingId != -1) {
$libKeyLink = $this->getLibKeyUrl($relatedUrl['url']);
if (!empty($libKeyLink)) {
return [
'success' => true,
'url' => $libKeyLink
];
} else {
return [
'success' => true,
'url' => $relatedUrl['url']
];
}
} else {
return [
'success' => true,
'url' => $relatedUrl['url']
];
];
}
}
}
Expand Down

0 comments on commit 27ebf39

Please sign in to comment.