Last active
October 9, 2021 02:05
-
-
Save SimonXIX/15ec4028f8e2a1ced242 to your computer and use it in GitHub Desktop.
Script to display new books information direct from Ex Libris Alma Analytics. This is an early prototype for a web-displayable automated new books list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# @name: new_books.php | |
# @version: 0.2 | |
# @license: GNU General Public License version 3 (GPLv3) <https://www.gnu.org/licenses/gpl-3.0.en.html> | |
# @purpose: Compile and display new books information for Imperial College Library | |
# @author: Simon Barron <s.barron@imperial.ac.uk> | |
# @acknowledgements: Based on a process by Ryan Edwards available at https://github.com/reedwards/automated-new-books-list | |
?> | |
<?php | |
$apikey=urlencode('xxxxxxxxxxxxxx'); | |
$baseurl = 'https://api-eu.hosted.exlibrisgroup.com/almaws/v1/'; | |
# The $path variable should be a path to a report made in Alma Analytics. | |
# | |
# It should be a report on the Physical Items subject area with the following filters: | |
# | |
# "Physical Item Details"."Receiving Date" >= timestampadd(sql_tsi_day,-7, current_date) | |
# "Bibliographic Details"."Suppressed From Discovery" is equal to / is in No | |
# "Bibliographic Details"."Bibliographic Level" is equal to / is in a; m | |
# | |
# (We also used ""Location"."Library Code" is equal to / is in ONE OF OUR LIBRARIES) | |
# | |
# In this example, the report returns the following fields: | |
# (Column numbers refer to the column numbers in the API output) | |
# | |
# "Bibliographic Details"."MMS Id" = Column4 | |
# "Bibliographic Details"."Title" = Column7 | |
# "Bibliographic Details"."Author" = Column1 | |
# "Bibliographic Details"."Publisher" = Colunm6 | |
# "Bibliographic Details"."Publication Date" = Column5 | |
# "Bibliographic Details"."ISBN" = Column2 | |
# "Location"."Library Name" = Column9 | |
# "Location."Location Name" = Column10 | |
# "Holding Details"."Permanent Call Number" = Column8 | |
# | |
$path='/folder/folder/report'; | |
# Perform Curl request on the Alma Analytics API | |
$ch = curl_init(); | |
$queryParams = '?' . urlencode('path') . '=' . urlencode($path) . '&' . urlencode('limit') . '=' . urlencode('1000') . '&' . urlencode('apikey') . '=' . $apikey; | |
curl_setopt($ch, CURLOPT_URL, $baseurl . 'analytics/reports' . $queryParams); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
# Turn the API response into useful XML | |
$xml = new SimpleXMLElement($response); | |
# For each row in the Analytics report, retrieve and display the appropriate data from the appropriate columns | |
foreach ($xml->QueryResult->ResultXml->rowset->Row as $row){ | |
# Strip trailing '/' from title field | |
echo '<strong>Title: </strong>' . '<a href=http://imp-primo.hosted.exlibrisgroup.com/primo_library/libweb/action/search.do?fn=search&vid=ICL_VU1&vl(freeText0)=' . (string) $row->Column4 . '>' . preg_replace('/\/$/','',(string) $row->Column7) . '</a>' . '<br />'; | |
# Only show author field if it's populated | |
if (!empty($row->Column1)){ | |
echo '<strong>Author: </strong>' . (string) $row->Column1 . '<br />'; | |
} | |
# Strip out everything except ISBN-13s | |
echo '<strong>ISBN: </strong>' . preg_replace('/(^|.*)(978.{10})(.*|$)/','$2',(string) $row->Column2) . '<br />'; | |
echo '<strong>Published: </strong>' . (string) $row->Column6 . ': ' . (string) $row->Column5 . '<br />'; | |
echo '<strong>Location: </strong>' . (string) $row->Column9 . ' ' . (string) $row->Column10 . ' (' . (string) $row->Column8 . ')' . '<br />'; | |
echo '<br />'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment