From 4a1d87ab5822b31f9aafe17bd7c59bd4ba880050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Mon, 25 Nov 2024 13:05:20 +0000 Subject: [PATCH] feat: handle records with multiple locations When there is more than one location, the 'Access Online' button opens a dropdown allowing the user to select with link to use based on item location. Ensure that you have more than one item for the record used for testing, and that they are not recorded as being found at the same location. Test plan: - search Aspen for the item you have added - click on the search result's title or 'More Info' button - Scroll to the 'Links' section, and open it. - Notice the doi link - Notice the LibKey link - Click the LibKey link - if LibKey was able to return a direct link to the text, this should take you to a PDF of the document via LibKey, which should open in a new tab.e 'Access Online' button - On the search results page (/Union/Search), open 'Show Edition(s)' on the record. Click the 'Access Online' link - select a location, click, and notice that the redirect behaviour remains the same. --- code/web/services/Record/AJAX.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/code/web/services/Record/AJAX.php b/code/web/services/Record/AJAX.php index 57e04d7a39..6fb67847ce 100644 --- a/code/web/services/Record/AJAX.php +++ b/code/web/services/Record/AJAX.php @@ -1996,10 +1996,18 @@ function viewItem(): array { if ($item->itemId == $itemId) { $relatedUrls = $item->getRelatedUrls(); foreach ($relatedUrls as $relatedUrl) { - return [ - 'success' => true, - 'url' => $relatedUrl['url'] - ]; + $libKeyLink = $this->getLibKeyUrl($relatedUrl['url']); + if (!empty($libKeyLink)) { + return [ + 'success' => true, + 'url' => $libKeyLink + ]; + } else { + return [ + 'success' => true, + 'url' => $relatedUrl['url'] + ]; + } } } } @@ -2017,4 +2025,11 @@ function viewItem(): array { 'modalButtons' => "", ]; } + + private function getLibKeyUrl($doiUrl) { + require_once ROOT_DIR . "/Drivers/LibKeyDriver.php"; + $libKeyDriver = new LibKeyDriver(); + return $libKeyDriver->getLibKeyLink($doiUrl); + } } +