-
Notifications
You must be signed in to change notification settings - Fork 0
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
Campus logic update #18
Open
wopsononock
wants to merge
10
commits into
main
Choose a base branch
from
campus-logic-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b3ae659
update REST client location
wopsononock c19f9ab
Added title to article scan request url and clarified comments
wopsononock 1187b85
Added logic to handle users with Barco, Unknown or blank campus field…
wopsononock 6d52407
Change Illiad endpoint to one that can handle OpenURL parameters nati…
wopsononock 694b73a
remove hsls special borrowers from block list
wopsononock 0b9730d
Route blank and unknown campus users to ULS Illiad
wopsononock 9fac725
Change HSLS Illiad base url
wopsononock babc8d3
Borrowing policy is simplified now. Route any non HSLS-campus user wi…
wopsononock 1677e4b
Remove Illiad API methods we no longer need, store Alma user record t…
wopsononock 5f05a40
Only check for LAW campus if we know user has a campus code value and…
wopsononock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,32 +4,6 @@ | |
# Uses this PHP Rest Client: https://github.com/tcdent/php-restclient | ||
# | ||
|
||
$openurlParams = array( | ||
'title', | ||
'author', | ||
'publisher', | ||
'location', | ||
'year', | ||
'oclc', | ||
'issn', | ||
'requesttype', | ||
'volume', | ||
'issue', | ||
'month', | ||
'atitle', | ||
'pages', | ||
'pickup', | ||
'notes', | ||
); | ||
|
||
//url encode user-submitted input from the query string | ||
$userSubmittedParams = array(); | ||
foreach ($openurlParams as $p) { | ||
if (isset($_GET[$p])){ | ||
$userSubmittedParams[$p] = urlencode($_GET[$p]); | ||
} | ||
} | ||
|
||
Class Alma { | ||
|
||
private $api; | ||
|
@@ -38,7 +12,7 @@ | |
*returns ExLibris API function | ||
*/ | ||
public function __construct(){ | ||
include_once 'vendor/tcdent/php-restclient/restclient.php'; | ||
include_once 'php-restclient/restclient.php'; | ||
include_once '../../configs/config.php'; | ||
|
||
$this->api = new RestClient([ | ||
|
@@ -87,137 +61,68 @@ public function getUserRecord($userId){ | |
|
||
class Illiad { | ||
|
||
private $api; | ||
|
||
/* | ||
*returns ILLiad API function | ||
*/ | ||
public function __construct($campus){ | ||
include_once 'vendor/tcdent/php-restclient/restclient.php'; | ||
include_once '../../configs/config.php'; | ||
$system=$this->librarySystem($campus); | ||
$this->api = new RestClient([ | ||
'base_url' => ILLIAD_API_CONFIG[$system]['BASE_URL'] . 'illiadwebplatform/', | ||
'headers' => ['Apikey'=>ILLIAD_API_CONFIG[$system]['KEY'], | ||
'Accept' => 'application/json; version=1', | ||
'Content-Type' => 'application/json', | ||
], | ||
]); | ||
} | ||
|
||
/* | ||
* Pitt has two library systems that serve users from different Alma "campuses" | ||
* @param string $campus the user's Alma campus | ||
* $return string The user's library system for ILLiad purposes | ||
*/ | ||
private function librarySystem($campus) { | ||
switch ($campus) { | ||
case "UPG": | ||
case "UPB": | ||
case "UPT": | ||
case "UPJ": | ||
case "PIT": | ||
return 'ULS'; | ||
break; | ||
case "HSLS": | ||
return 'HSLS'; | ||
break; | ||
} | ||
} | ||
|
||
/* | ||
* Does Pitt user also have an existing ILLiad account? | ||
* @param string $user A Pitt username | ||
* @return bool | ||
*/ | ||
public function userExists($user){ | ||
$illiadUserRequest = $this->api->get("Users/[email protected]"); | ||
|
||
//ILLiad user exists | ||
if($illiadUserRequest->info->http_code == 200) { | ||
return true; | ||
} | ||
//Couldn't find ILLiad user | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/* | ||
* Construct link to appropriate ILLiad request form | ||
* @param string $campus Which Alma "campus" does the user belong to? | ||
* @param array $params Contains url-encoded entries from the query string to determine request type and prepopulate ILLiad fields | ||
* @return string The complete ILLiad request form URL | ||
*/ | ||
public function buildUrl($campus, $params) { | ||
public function buildUrl($campus) { | ||
// Service address | ||
if ($this->librarySystem($campus)=="ULS") { | ||
$url = 'https://pitt-illiad-oclc-org.pitt.idm.oclc.org/illiad/illiad.dll'; | ||
} | ||
elseif ($this->librarySystem($campus)=="HSLS") { | ||
$url = 'https://illiad.hsls.pitt.edu/illiad/illiad.dll'; | ||
if ($campus==="HSLS") { | ||
$url = 'https://illiad.hsls.pitt.edu/illiad/illiad.dll/AtlasAuthPortal/?Action=10&Form=30&'; | ||
} | ||
// Action and Form | ||
switch ($params['requesttype']) { | ||
case 'book': | ||
$url .= '?Action=10&Form='.($campus === 'HSLS' ? '30' : '21'); | ||
break; | ||
case 'chapter': | ||
$url .= '?Action=10&Form=23'; | ||
break; | ||
case 'article': | ||
$url .= '?Action=10&Form=22'; | ||
break; | ||
} | ||
|
||
// Parameters | ||
$map = array(); | ||
switch ($params['requesttype']) { | ||
case 'book': | ||
$map = array('LoanTitle' => 'title', 'LoanAuthor' => 'author', 'LoanPublisher' => 'publisher', 'LoanPlace' => 'location', 'LoanDate' => 'year', 'ESPNumber' => 'oclc'); | ||
break; | ||
case 'article': | ||
// article specific | ||
$map = array('PhotoJournalVolume' => 'volume', 'PhotoJournalIssue' => 'issue', 'PhotoJournalMonth' => 'month', 'PhotoArticleTitle' => 'atitle', 'PhotoJournalInclusivePages' => 'pages'); | ||
break; | ||
case 'chapter': | ||
// both articles and chapters | ||
$map = array_merge($map, array('PhotoJournalTitle' => 'title', 'PhotoItemAuthor' => 'author', 'PhotoItemPublisher' => 'publisher', 'PhotoItemPlace' => 'location', 'PhotoJournalYear' => 'year', 'ESPNumber' => 'oclc')); | ||
break; | ||
else { | ||
$url = 'https://pitt-illiad-oclc-org.pitt.idm.oclc.org/illiad/illiad.dll/OpenURL?'; | ||
} | ||
foreach ($map as $k => $v) { | ||
$url .= '&'.$k.'='.$params[$v]; | ||
$userQueryString = ''; | ||
//sanitize user-generated query string parameters | ||
foreach($_GET as $k=>$v) { | ||
//php replaces query string parameter keys containing dots as underscores, so rft.title becomes rft_title. Change that back with str_replace, but only for rft keys. rfr, for example, uses an underscore natively, like rfr_id | ||
$userQueryString .= str_replace("rft_", "rft.", urlencode($k)).'='.urlencode($v).'&'; | ||
} | ||
//the last param should not be followed by & | ||
$url .= rtrim($userQueryString,'&'); | ||
return $url; | ||
} | ||
} | ||
|
||
//These Alma user groups aren't permitted to place external requests | ||
$noExternalBorrowing = array('LAWSPBORROWER','PATPURGE','PITTLIBASSIGNMENT','PROBLEM','ULSSPBORROWER','ULSSPRECIPROCAL','UPPROGRAM'); | ||
|
||
//Get the patron's Pitt username | ||
$user = new Alma(); | ||
$userId = $user->getUserId(); | ||
$requestStatus = ''; | ||
|
||
//if their account has all the info we need | ||
if ($user->getUserRecord($userId) && $user->getUserRecord($userId)->campus_code && $user->getUserRecord($userId)->user_group->value) { | ||
//this user group isn't permitted to place external requests | ||
if ($user->getUserRecord($userId)->user_group->value == 'UPPROGRAM') { | ||
$requestStatus='program'; | ||
if (($userRecord = $user->getUserRecord($userId)) && $userRecord->campus_code && $userRecord->user_group->value) { | ||
//Find user's Alma usergroup and campus | ||
//If the blank Campus dropdown menu option in Alma is saved for a user, their user campus_code object doesn't get a value, just a blank description property | ||
if (!property_exists($userRecord->campus_code,'value')) { | ||
$campus = 'BLANK'; | ||
} | ||
else { | ||
//continue on with the existing workflow | ||
//Determine which Alma campus the user belongs to | ||
$campus = $user->getUserRecord($userId)->campus_code->value; | ||
//Does user have an ILLiad account? We'll check based on their campus and corresponding library system | ||
$illiad = new Illiad($campus); | ||
$illiadUserExists = $illiad->userExists($userId); | ||
//construct a link to the appropriate ILLiad form | ||
$illiadUrl = $illiad->buildUrl($campus, $userSubmittedParams); | ||
//if they already have an ILLiad account | ||
if ($illiadUserExists) { | ||
//send them immediately to the ILLiad request form | ||
//if not, the html instructions below will display by default | ||
header("Location: $illiadUrl"); | ||
//Otherwise, just take the campus value straight from the user record | ||
else{ | ||
$campus = $userRecord->campus_code->value; | ||
//Barco Law Library users do not participate in Illiad, so we'll handle them separately later | ||
if ($userRecord->campus_code->value==='LAW' && $requestStatus !== 'specialBorrower') { | ||
$requestStatus='lawPatron'; | ||
} | ||
} | ||
|
||
//Determine Alma usergroup | ||
$userGroup = $userRecord->user_group->value; | ||
//Check that against the blocklist for special borrowers | ||
if (in_array($userGroup,$noExternalBorrowing)) { | ||
$requestStatus='specialBorrower'; | ||
} | ||
if (!$requestStatus) { | ||
$illiad = new Illiad(); | ||
//construct a link to the appropriate ILLiad form | ||
$illiadUrl = $illiad->buildUrl($campus); | ||
//send them to ther campus's ILLiad request form | ||
header("Location: $illiadUrl"); | ||
} | ||
} | ||
//Couldn't get Alma user record. | ||
else { | ||
|
@@ -240,23 +145,27 @@ public function buildUrl($campus, $params) { | |
<div id="main-content"> | ||
<h1>Request This Item</h1> | ||
<?php | ||
if ($requestStatus == 'almaError') { | ||
echo <<<ALMA_API_ERROR | ||
<p>Error: Failed to connect to your library account. Please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a> for assistance.</p> | ||
switch ($requestStatus) { | ||
case "almaError": | ||
echo <<<ALMA_API_ERROR | ||
<p>Error: Failed to connect to your library account. Please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a> for assistance.</p> | ||
ALMA_API_ERROR; | ||
break; | ||
case "specialBorrower": | ||
echo <<<SPECIAL_BORROWER | ||
<p>Special borrowers cannot order books from other libraries. Please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a> for assistance.</p> | ||
SPECIAL_BORROWER; | ||
break; | ||
case "lawPatron": | ||
echo <<<LAW_PATRON | ||
<p>Law School users, please see <a href="https://www.library.law.pitt.edu/research/interlibrary-loan-delivery">https://www.library.law.pitt.edu/research/interlibrary-loan-delivery</a> for interlibrary loan inforrmation.</p> | ||
LAW_PATRON; | ||
break; | ||
default: | ||
echo <<<OTHER_ERROR | ||
<p>There is a problem with your request. Please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a> for assistance.</p> | ||
OTHER_ERROR; | ||
} | ||
elseif ($requestStatus == 'program'){ | ||
echo <<<PROGRAM_PARTICIPANT | ||
<p>Pitt program participants cannot order books from other libraries. Please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a> for assistance.</p> | ||
PROGRAM_PARTICIPANT; | ||
} | ||
else{ | ||
echo <<<NOILLIADUSER | ||
<p>Hi, there! Prior to completing your request, and due to changes with our materials sharing provider, we ask that you <a href="$illiadUrl">complete a one-time registration with our interlibrary-loan service</a> if you have not already done so.</p> | ||
<p>After registration, just complete the request in the form provided and we will have your materials on their way to you as quickly as possible!</p> | ||
<p>If you need any additional assistance, please <a href="https://www.library.pitt.edu/ask-us">Ask Us</a></p> | ||
NOILLIADUSER; | ||
} | ||
?> | ||
</div> | ||
</body> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sourced here: https://github.com/tcdent/php-restclient , and is maintained, so we probably should be using composer for dependency management (or a git submodule).