Last active
June 21, 2018 22:47
-
-
Save richshea/0857f5cfae6bc12b45380aa1a59d37fc to your computer and use it in GitHub Desktop.
Permalink to Primo using Alma MMS ID
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 | |
// Set these Customer Parameters to make this service work for your Institution. The apiKey should have acces to the Primo Search API and can be set up in the Ex Libris Developers Network. | |
$apiKey = "<Your API Key Here>"; | |
//The vid, searchscope, and searchTab parameters are the same as the ones used for deep links described here: | |
//https://developers.exlibrisgroup.com/primo/apis/deeplinks/brief | |
$vid = "BRAND"; | |
$searchScope = "ALMA"; | |
$searchTab = "alma"; | |
//for the two BaseURL parameters, include the protocol, i.e. https:// or http:// | |
$primoBaseURL = "https://search.library.brandeis.edu"; | |
$apiBaseURL = "https://api-na.hosted.exlibrisgroup.com"; | |
//If the URL includes an mms parameter, PHP will run the code below and try to use the supplied value as an MMS ID | |
//to search in Primo. If a value that is not an MMS ID is supplied, you are sent to Primo and shown a "Record cannot be displayed" message | |
if ($_GET['mms'] != "") { | |
// This code was taken from the Developers Network PHP API code generator for the Primo Search API: | |
// https://developers.exlibrisgroup.com/primo/apis/search | |
$ch = curl_init(); | |
$url = $apiBaseURL.'/primo/v1/search'; | |
$queryParams = '?' . urlencode('vid') . '=' . urlencode($vid) . '&' . urlencode('tab') . '=' . urlencode($searchTab) . '&' . urlencode('scope') . '=' . urlencode($searchScope) . '&' . urlencode('q') . '=' . urlencode('any,contains,') . urlencode($_GET['mms']) . '&' . urlencode('lang') . '=' . urlencode('eng') . '&' . urlencode('offset') . '=' . urlencode('0') . '&' . urlencode('limit') . '=' . urlencode('10') . '&' . urlencode('sort') . '=' . urlencode('rank') . '&' . urlencode('pcAvailability') . '=' . urlencode('true') . '&' . urlencode('getMore') . '=' . urlencode('0') . '&' . urlencode('conVoc') . '=' . urlencode('true') . '&' . urlencode('apikey') . '=' . urlencode($apiKey); | |
curl_setopt($ch, CURLOPT_URL, $url . $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); | |
//take the json formatted text returned by the API call and make it into a PHP object | |
$responseDecoded = json_decode($response); | |
//The second parameter returns a URL that ends in /pnxs/L/<Primo_Record_Id>, so we access that link and then | |
//split it into an array that holds the beginning of the URL in the zeroeth element and the Primo record ID in the first element | |
$recordIdArray = explode("/pnxs/L/", $responseDecoded->docs[0]->{"@id"}); | |
//assign the Primo record ID into its own variable for code clarity I suppose | |
$recordId = $recordIdArray[1]; | |
//Build the URL to the Primo Full Dsiplay using the customer parameters set above and the recordID | |
$redirectURL = "$primoBaseURL/primo-explore/fulldisplay?docid=$recordId&context=L&vid=$vid&search_scope=$searchScope&tab=$searchTab&lang=en_US"; | |
//The header function is used to send the user to the Primo page. No html can be output before using this function | |
header("Location: $redirectURL"); | |
} else { //if no MMS ID parameter is supplied we show a simple form for supplying one | |
echo "<html><head></head><body><form> | |
<label>Enter MMS ID: | |
<input name='mms' /></label> | |
<input type='submit' /></form></body>"; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment