Skip to content

Commit

Permalink
Merge pull request #147 from Chloe070196/libkey_integration
Browse files Browse the repository at this point in the history
Libkey integration - requested changes
  • Loading branch information
Chloe070196 authored Dec 4, 2024
2 parents 305a96d + 22cc01d commit 62e9642
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
11 changes: 8 additions & 3 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

class LibKeyDriver {

public function getLibKeyLink(string $doiUrl): string | null {
if (!$this->containsDoi($doiUrl)) {
return null;
}
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();
if (!$settings->find(true)) {
return null;
}
$curlWrapper = new CurlWrapper;
$response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $this->extractDoi($doiUrl) . "?access_token=" . $settings->apiKey);
Expand All @@ -21,4 +23,7 @@ public function extractDoi(string $url): string {
$doi = str_replace(["https://doi.org/", "http://"], "", $url);
return $doi;
}
public function containsDoi(string $url): bool {
return preg_match('/10.\d{4,9}\/[-._;()\/:A-Za-z0-9]/', $url);
}
}
23 changes: 9 additions & 14 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 @@ -1337,15 +1330,15 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
];
} elseif (count($relatedUrls) == 1) {

$libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']);
if (!empty($libKeyLink)) {
if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($relatedUrls[0]['url'])) {
$libKeyLink = $this->getLibKeyUrl($relatedUrls[0]['url']);
$title = translate([
'text' => 'Access Online',
'isPublicFacing' => true,
]);
$actions[] = [
'title' => $title,
'url' => $libKeyLink,
'url' => $libKeyLink ? $libKeyLink : $relatedUrls[0]['url'],
'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 && !empty($links[0]['url'])) {
$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 @@ -1963,17 +1963,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 && !empty($relatedUrl['url'])) {
$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
4 changes: 0 additions & 4 deletions code/web/sys/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3872,10 +3872,6 @@ public function getAdminActions() {
'Administer All System Messages',
'Administer Library System Messages',
]);
$sections['local_enrichment']->addAction(new AdminAction('System Messages', 'System Messages allow you to display messages to your patrons in specific locations.', '/Admin/SystemMessages'), [
'Administer All System Messages',
'Administer Library System Messages',
]);

$sections['third_party_enrichment'] = new AdminSection('Third Party Enrichment');
$sections['third_party_enrichment']->addAction(new AdminAction('Accelerated Reader Settings', 'Define settings to load Accelerated Reader information directly from Renaissance Learning.', '/Enrichment/ARSettings'), 'Administer Third Party Enrichment API Keys');
Expand Down
7 changes: 0 additions & 7 deletions code/web/sys/DBMaintenance/version_updates/24.12.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ function getUpdates24_12_00(): array {
//alexander - PTFS-Europe

//chloe - PTFS-Europe
'create_libkey_module' => [
'title' => 'Create LibKey Module',
'description' => 'Add LibKey to the list of modules',
'sql' => [
"INSERT INTO modules (name) VALUES ('LibKey')",
],
], // create_libkey_module
'create_libkey_permissions' => [
'title' => 'Create LibKey Permissions',
'description' => 'Add an LibKey permission section containing the Administer LibKey Settings permission',
Expand Down

0 comments on commit 62e9642

Please sign in to comment.