Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25.01.00 libkey integration for ebsco records #2181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?php

class LibKeyDriver {
public function getLibKeyLink(string $doiUrl): string | null {
if (!$this->containsDoi($doiUrl)) {
return null;
}
public function getLibKeyResult($data): array | null {
require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php';
$activeLibrary = Library::getActiveLibrary();
$settings = new LibKeySetting();
Expand All @@ -13,16 +10,40 @@ public function getLibKeyLink(string $doiUrl): string | null {
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);
$doi = $this->getDoi($data);
if (!$doi) {
return null;
}
$response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $doi . "?access_token=" . $settings->apiKey . "&include=journal");
if (empty($response)) {
return null;
}
return json_decode($response, true)["data"]["bestIntegratorLink"]["bestLink"];
return json_decode($response, true);
}
public function extractDoi(string $url): string {
$doi = str_replace(["https://doi.org/", "http://"], "", $url);
return $doi;

private function getDoi($data): string | null {
if (!is_object($data)) {
if (!$this->containsDoi($data)) {
return null;
}
return $this->extractDoiFromUrl($data);
}
return $this->findDoiInArray((array) $data);
}

private function findDoiInArray(array $uiList): string | null {
foreach ($uiList as $ui) {
if (!is_array($ui) && !is_object($ui) && $this->containsDoi($ui)) {
return $ui;
}
}
return null;
}

private function extractDoiFromUrl(string $url): string {
return str_replace(["https://doi.org/", "http://"], "", $url);
}

public function containsDoi(string $url): bool {
return preg_match('/10.\d{4,9}\/[-._;()\/:A-Za-z0-9]/', $url);
}
Expand Down
2 changes: 1 addition & 1 deletion code/web/RecordDrivers/MarcRecordDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ function createActionsFromUrls($relatedUrls, $itemInfo = null, $variationId = 'a
private function getLibKeyUrl($doiUrl) {
require_once ROOT_DIR . "/Drivers/LibKeyDriver.php";
$libKeyDriver = new LibKeyDriver();
return $libKeyDriver->getLibKeyLink($doiUrl);
return $libKeyDriver->getLibKeyResult($doiUrl)["data"]["bestIntegratorLink"]["bestLink"];
}

private $catalogDriver = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<div class="result-tools-horizontal btn-toolbar" role="toolbar">
{* More Info Link, only if we are showing other data *}
{if !empty($showMoreInfo)}
{if $showMoreInfo !== false && !empty($libKeyUrl)}
<div class="btn-group btn-group-sm">
<a href="{$libKeyUrl}" class="btn btn-sm btn-tools" target="_blank" aria-label="{translate text="Access Online" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"><i class="fas fa-external-link-alt" role="presentation"></i> {translate text="Access Online" isPublicFacing=true}</a>
</div>
{/if}
{if $showMoreInfo !== false}
<div class="btn-group btn-group-sm">
<a href="{if !empty($summUrl)}{$summUrl}{else}{$recordDriver->getLinkUrl()}{/if}" class="btn btn-sm btn-tools" onclick="AspenDiscovery.EBSCO.trackEdsUsage('{$recordDriver->getPermanentId()}')" target="_blank" aria-label="{translate text="More Info" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"><i class="fas fa-external-link-alt" role="presentation"></i> {translate text="More Info" isPublicFacing=true}</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<div class="result-tools-horizontal btn-toolbar" role="toolbar">
{* More Info Link, only if we are showing other data *}
{if !empty($showMoreInfo)}
{if $showMoreInfo !== false && !empty($libKeyUrl)}
<div class="btn-group btn-group-sm">
<a href="{$libKeyUrl}" class="btn btn-sm btn-tools" target="_blank" aria-label="{translate text="Access Online" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"><i class="fas fa-external-link-alt" role="presentation"></i> {translate text="Access Online" isPublicFacing=true}</a>
</div>
{/if}
{if $showMoreInfo !== false}
<div class="btn-group btn-group-sm">
<a href="{if !empty($summUrl)}{$summUrl}{else}{$recordDriver->getLinkUrl()}{/if}" class="btn btn-sm btn-tools" onclick="AspenDiscovery.EBSCO.trackEdsUsage('{$recordDriver->getPermanentId()}')" target="_blank" aria-label="{translate text="More Info" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"><i class="fas fa-external-link-alt" role="presentation"></i> {translate text="More Info" isPublicFacing=true}</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<div class="coversColumn col-xs-3 col-sm-3{if empty($viewingCombinedResults)} col-md-3 col-lg-2{/if} text-center" aria-hidden="true" role="presentation">
{if $disableCoverArt != 1 && !empty($bookCoverUrlMedium)}
<a href="{$summUrl}" onclick="AspenDiscovery.EBSCO.trackEdsUsage('{$summId}')" target="_blank" aria-hidden="true">
<img src="{$bookCoverUrlMedium}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{if !empty($libKeyCoverImageUrl) && !$retracted}
<img src="{$libKeyCoverImageUrl}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{else}
<img src="{$bookCoverUrlMedium}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{/if}
</a>
{/if}
</div>
Expand All @@ -19,6 +23,11 @@
</a>
</div>
</div>
{if $retracted}
<div class="alert alert-warning btn" id="retraction-warning" role="alert" aria-live="polite">
<strong><a href="{$libKeyUrl}" target="_blank"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" aria-label="{translate text="Retracted" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"></span> {translate text='Retracted' isPublicFacing=true}</a> <i class="fas fa-external-link-alt" role="presentation"></i></strong>
</div>
{/if}

{if !empty($summAuthor)}
<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<div class="coversColumn col-xs-3 col-sm-3{if empty($viewingCombinedResults)} col-md-3 col-lg-2{/if} text-center" aria-hidden="true" role="presentation">
{if $disableCoverArt != 1 && !empty($bookCoverUrlMedium)}
<a href="{$summUrl}" onclick="AspenDiscovery.EBSCO.trackEdsUsage('{$summId}')" target="_blank" aria-hidden="true">
<img src="{$bookCoverUrlMedium}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{if !empty($libKeyCoverImageUrl) && !$retracted}
<img src="{$libKeyCoverImageUrl}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{else}
<img src="{$bookCoverUrlMedium}" class="listResultImage img-thumbnail {$coverStyle}" alt="{translate text='Cover Image' inAttribute=true isPublicFacing=true}">
{/if}
</a>
{/if}
</div>
Expand All @@ -19,6 +23,11 @@
</a>
</div>
</div>
{if $retracted}
<div class="alert alert-warning btn" id="retraction-warning" role="alert" aria-live="polite">
<strong><a href="{$libKeyUrl}" target="_blank"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" aria-label="{translate text="Retracted" isPublicFacing=true inAttribute=true} ({translate text="opens in a new window" isPublicFacing=true inAttribute=true})"></span> {translate text='Retracted' isPublicFacing=true}</a> <i class="fas fa-external-link-alt" role="presentation"></i></strong>
</div>
{/if}

{if !empty($summAuthor)}
<div class="row">
Expand Down
9 changes: 9 additions & 0 deletions code/web/release_notes/25.01.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
//alexander

//chloe
### LibKey integration Updates

For records found in an Articles and Database search through the EBSCO host or EBSCO EDS integration:
- patrons of libraries with a LibKey subscription can access full-text document using an 'Access Online' button to the right of 'More Info' on search results. (*CZ*)
- if the LibKey API does not return a direct link, then 'Access Online' does not show. (*CZ*)
- for EBSCO EDS and host records, if the LibKey API sends back a cover image url, show this cover image on the search result. (*CZ*)
- if the results from the LibKey API indicate an article has been retracted, they are marked as such. (*CZ*)
- for retracted articles, a link to a LibKey page giving information on the retraction is displayed. (*CZ*)
- for retracted articles, the 'Access Online' button is not displayed. (*CZ*)

//pedro

Expand Down
2 changes: 1 addition & 1 deletion code/web/services/Record/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ function viewItem(): array {
private function getLibKeyUrl($doiUrl) {
require_once ROOT_DIR . "/Drivers/LibKeyDriver.php";
$libKeyDriver = new LibKeyDriver();
return $libKeyDriver->getLibKeyLink($doiUrl);
return $libKeyDriver->getLibKeyResult($uniqueIdentifierList)["data"]["bestIntegratorLink"]["bestLink"];
}
}

23 changes: 23 additions & 0 deletions code/web/sys/SearchObject/EbscoEdsSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,22 @@ public function getResultRecordHTML() {
$current = &$this->lastSearchResults->Data->Records[$x];
$interface->assign('recordIndex', $x + 1);
$interface->assign('resultIndex', $x + 1 + (($this->page - 1) * $this->limit));
if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($this->lastSearchResults->Data->Records[$x]->RecordInfo->BibRecord->BibEntity->Identifiers)) {
foreach ($this->lastSearchResults->Data->Records[$x]->RecordInfo->BibRecord->BibEntity->Identifiers as $ui) {
if ($ui->Type == "doi") {
$libKeyResult = $this->getLibKeyResult($ui->Value);
if (isset($libKeyResult['data']['retractionNoticeUrl'])) {
$interface->assign('libKeyUrl', $libKeyResult['data']['retractionNoticeUrl']);
$interface->assign('retracted', true);
break;
}
$interface->assign('libKeyUrl', $libKeyResult["data"]["bestIntegratorLink"]["bestLink"]);
$interface->assign('libKeyCoverImageUrl', $libKeyResult['included'][0]['coverImageUrl']);
$interface->assign('retracted', false);
break;
}
}
}

require_once ROOT_DIR . '/RecordDrivers/EbscoRecordDriver.php';
$record = new EbscoRecordDriver($current);
Expand Down Expand Up @@ -907,4 +923,11 @@ public function getResearchStarters($searchTerm = null) {

return $researchStarters;
}

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

}
26 changes: 21 additions & 5 deletions code/web/sys/SearchObject/EbscohostSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,18 @@ public function getResultRecordHTML() {
$current = &$this->lastSearchResults->SearchResults->records->rec[$x];
$interface->assign('recordIndex', $x + 1);
$interface->assign('resultIndex', $x + 1 + (($this->page - 1) * $this->limit));

if (Library::getActiveLibrary()->libKeySettingId != -1 && !empty($current->header->controlInfo->artinfo->ui)) {
$libKeyResult = $this->getLibKeyResult($current->header->controlInfo->artinfo->ui);
if (isset($libKeyResult['data']['retractionNoticeUrl'])) {
$interface->assign('libKeyUrl', $libKeyResult['data']['retractionNoticeUrl']);
$interface->assign('retracted', true);
break;
}
$interface->assign('libKeyUrl', $libKeyResult["data"]["bestIntegratorLink"]["bestLink"]);
$interface->assign('libKeyCoverImageUrl', $libKeyResult['included'][0]['coverImageUrl']);
$interface->assign('retracted', false);
break;
}
require_once ROOT_DIR . '/RecordDrivers/EbscohostRecordDriver.php';
$record = new EbscohostRecordDriver($current);
if ($record->isValid()) {
Expand Down Expand Up @@ -283,7 +294,7 @@ public function getCombinedResultHTML() {
global $interface;
$html = [];
//global $logger;
//$logger->log(print_r($this->lastSearchResults, true), Logger::LOG_WARNING);
//$logger->log(print_r($this->lastSearchResults, true), Logger::LOG_ERROR);
if (isset($this->lastSearchResults->SearchResults->records)) {
for ($x = 0; $x < count($this->lastSearchResults->SearchResults->records->rec); $x++) {
$current = &$this->lastSearchResults->SearchResults->records->rec[$x];
Expand Down Expand Up @@ -814,14 +825,13 @@ public function getRecordDriverForResult($current): EbscohostRecordDriver {
function getBrowseRecordHTML() {
global $interface;
$html = [];
//global $logger;
//$logger->log(print_r($this->lastSearchResults, true), Logger::LOG_WARNING);
global $logger;

if (isset($this->lastSearchResults->SearchResults->records)) {
for ($x = 0; $x < count($this->lastSearchResults->SearchResults->records->rec); $x++) {
$current = &$this->lastSearchResults->SearchResults->records->rec[$x];
$interface->assign('recordIndex', $x + 1);
$interface->assign('resultIndex', $x + 1 + (($this->page - 1) * $this->limit));

require_once ROOT_DIR . '/RecordDrivers/EbscohostRecordDriver.php';
$record = new EbscohostRecordDriver($current);
if ($record->isValid()) {
Expand Down Expand Up @@ -952,4 +962,10 @@ public function getFilterList() {
}
return $list;
}

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