Skip to content

Commit

Permalink
feat: Access Online uses LibKey link
Browse files Browse the repository at this point in the history
Setting up for testing:

Ensure that the ILS of your choice
contains records which Aspen will recognise as
eContent.

If using Koha as Aspen's ILS:

You will need to create a new item
type that matches the item types Aspen currently
recognises as eContent.

I would recommend using 'online' (for the full
list: KohaProcessorJava.php)

You will also likely need to add a new record that
has a DOI - I recommend selecting an open Access
research paper. The DOI must be included in field
856 u.

Once Aspen has indexed the newly added record,
testing can start.

Note: this assume that the LibKey settings has
been set up. If not, see the test plan in
commit 'feat: Administer LibKey Settings'

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
- Notice the 'Access Online' button
- 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.
- Click the 'Access Online' button. The redirect
behaviour here should be exactly the same as
what occurred when clicking the LibKey link.
- On the search results page (/Union/Search),
open 'Show Edition(s)' on the record. Click the
'Access Online' link - again, notice that the
redirect behaviour is the same.
  • Loading branch information
Chloe070196 committed Dec 2, 2024
1 parent 293b207 commit 3956f87
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 23 deletions.
20 changes: 20 additions & 0 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class LibKeyDriver {

public function getLibKeyLink($doi) {
require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php';
$activeLibrary = Library::getActiveLibrary();
$settings = new LibKeySetting();
$settings->whereAdd("id=$activeLibrary->libKeySettingId");
if ($settings->find(true)) {
$settings->fetch();
}
$curlWrapper = new CurlWrapper;
$response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $doi . "?access_token=" . $settings->apiKey);
if (empty($response)) {
return null;
}
return json_decode($response, true)["data"]["bestIntegratorLink"]["bestLink"];
}
}
81 changes: 58 additions & 23 deletions code/web/RecordDrivers/MarcRecordDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ public function getRecordActions($relatedRecord, $variationId, $isAvailable, $is
}
}

$this->_actions[$variationId] = array_merge($this->_actions[$variationId], $this->createActionsFromUrls($relatedUrls, null, $variationId));
$this->_actions[$variationId] = array_merge($this->_actions[$variationId], $this->createActionsFromUrls($relatedUrls, $relatedRecord, $variationId));

if ($interface->getVariable('displayingSearchResults')) {
$showHoldButton = $interface->getVariable('showHoldButtonInSearchResults');
Expand Down Expand Up @@ -1314,6 +1314,14 @@ 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 @@ -1328,34 +1336,52 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
'target' => '_blank',
];
} elseif (count($relatedUrls) == 1) {
$urlInfo = reset($relatedUrls);

//Revert to access online per Karen at CCU. If people want to switch it back, we can add a per library switch
$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
]);
$alt = 'Available online from ' . $urlInfo['source'];
$action = $configArray['Site']['url'] . '/' . $this->getModule() . '/' . $this->id . "/AccessOnline?index=$i&variationId=$variationId";
$fileOrUrl = isset($urlInfo['url']) ? $urlInfo['url'] : $urlInfo['file'];
if (strlen($fileOrUrl) > 0) {
if (strlen($fileOrUrl) >= 3) {
$extension = strtolower(substr($fileOrUrl, strlen($fileOrUrl), 3));
if ($extension == 'pdf') {
$title = translate([
'text' => 'Access PDF',
'isPublicFacing' => true,
]);
}
}
$libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']);
if (!empty($libKeyLink)) {
$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
]);
$actions[] = [
'url' => $action,
'redirectUrl' => $fileOrUrl,
'title' => $title,
'url' => $libKeyLink,
'requireLogin' => false,
'alt' => $alt,
'type' => 'access_online',
'id' => "accessOnline_{$this->getId()}",
'target' => '_blank',
];

} else {
$urlInfo = reset($relatedUrls);

//Revert to access online per Karen at CCU. If people want to switch it back, we can add a per library switch
$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
]);
$alt = 'Available online from ' . $urlInfo['source'];
$action = $configArray['Site']['url'] . '/' . $this->getModule() . '/' . $this->id . "/AccessOnline?index=$i&variationId=$variationId";
$fileOrUrl = isset($urlInfo['url']) ? $urlInfo['url'] : $urlInfo['file'];
if (strlen($fileOrUrl) > 0) {
if (strlen($fileOrUrl) >= 3) {
$extension = strtolower(substr($fileOrUrl, strlen($fileOrUrl), 3));
if ($extension == 'pdf') {
$title = translate([
'text' => 'Access PDF',
'isPublicFacing' => true,
]);
}
}
$actions[] = [
'url' => $action,
'redirectUrl' => $fileOrUrl,
'title' => $title,
'requireLogin' => false,
'alt' => $alt,
'target' => '_blank',
];
}
}
} else {
foreach ($relatedUrls as $urlInfo) {
Expand Down Expand Up @@ -1391,6 +1417,11 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
return $actions;
}

private function getLibKeyUrl($doiUrl) {
require_once ROOT_DIR . "/Drivers/LibKeyDriver.php";
$libKeyDriver = new LibKeyDriver();
return $libKeyDriver->getLibKeyLink($doiUrl);
}

private $catalogDriver = null;

Expand Down Expand Up @@ -1659,6 +1690,10 @@ public function getMoreDetailsOptions() {
$interface->assign('periodicalIssues', $issues);
}
$links = $this->getLinks();
$libKeyLink = $this->getLibKeyUrl($links[0]['url']);
if (!empty($libKeyLink)) {
$links[] = ['title' => $libKeyLink, 'url' => $libKeyLink];
}
$interface->assign('links', $links);
$interface->assign('show856LinksAsTab', $library->getGroupedWorkDisplaySettings()->show856LinksAsTab);
$interface->assign('showItemDueDates', $library->getGroupedWorkDisplaySettings()->showItemDueDates);
Expand Down

0 comments on commit 3956f87

Please sign in to comment.