Skip to content

Commit

Permalink
Merge pull request #141 from multnomah-county-it/dev
Browse files Browse the repository at this point in the history
New remove_url function
  • Loading branch information
john-c-houser authored Feb 7, 2024
2 parents 8b24e51 + 944cd85 commit a5403c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/Libilsws.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,10 +1051,16 @@ public function get_policy ($token = null, $policy_name = null, $policy_key = nu
return $this->send_get("$this->base_url/policy/$policy_name/key/$policy_key", $token, []);
}

private function trim_trailing_punct ($string)
/**
* Removes URLs from the trailing end of a string
*
* @param string $string String to be modifed
* @return string $string Modifed string
*/

private function remove_url ($string)
{
$string = trim($string);
$string = preg_replace('#^(.*)([[:punct:]]+)$#', '$1', $string);
$string = preg_replace('#^(.*)(http)(s*)(:\/\/)(.*)$#', '$1', $string);

return trim($string);
}
Expand All @@ -1074,33 +1080,31 @@ public function get_library_paging_list ($token = null, $library_key = null)
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('library_key', $library_key, 'r:#^[A-Z]$#');

$response = $this->send_get("$this->base_url/circulation/holdItemPullList/key/$library_key", $token,
['includeFields' => 'pullList{holdRecord{holdType,status,pickupLibrary},item{call{bib{key},callNumber,sortCallNumber},barcode,currentLocation{description}itemType}}']);
$include_fields = 'pullList{holdRecord{holdType,status,pickupLibrary},item{call{bib{author,title},callNumber,sortCallNumber},barcode,currentLocation{description}itemType}}';
$response = $this->send_get("$this->base_url/circulation/holdItemPullList/key/$library_key", $token, ['includeFields' => $include_fields]);

if ( ! empty($response['fields']['pullList']) ) {
foreach ($response['fields']['pullList'] as $hold) {

$bib = $this->get_bib($token, $hold['fields']['item']['fields']['call']['fields']['bib']['key'], 'bib{100_a,100_d,245_a}');

$record = [];
$record['author'] = !empty($bib['100_a']) ? $this->trim_trailing_punct($bib['100_a']) : '';
if ( !empty($bib['100_d']) ) {
$record['author'] = $record['author'] . ', ' . $bib['100_d'];
}
$record['title'] = !empty($bib['245_a']) ? $this->trim_trailing_punct($bib['245_a']) : '';

$record['holdType'] = $hold['fields']['holdRecord']['fields']['holdType'];
$record['status'] = $hold['fields']['holdRecord']['fields']['status'];
$record['pickupLibrary'] = $hold['fields']['holdRecord']['fields']['pickupLibrary']['key'];
$record['item'] = $hold['fields']['item']['key'];
$record['bib'] = $hold['fields']['item']['fields']['call']['fields']['bib']['key'];
$record['author'] = $hold['fields']['item']['fields']['call']['fields']['bib']['fields']['author'];
$record['title'] = $hold['fields']['item']['fields']['call']['fields']['bib']['fields']['title'];
$record['callNumber'] = $hold['fields']['item']['fields']['call']['fields']['callNumber'];
$record['sortCallNumber'] = $hold['fields']['item']['fields']['call']['fields']['sortCallNumber'];
$record['barcode'] = $hold['fields']['item']['fields']['barcode'];
$record['currentLocation'] = $hold['fields']['item']['fields']['currentLocation']['key'];
$record['locationDescription'] = $hold['fields']['item']['fields']['currentLocation']['fields']['description'];
$record['itemType'] = $hold['fields']['item']['fields']['itemType']['key'];


// Remove URL from author field
$record['author'] = $this->remove_url($record['author']);

array_push($list, $record);
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/register_patron.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'language' => 'SOMALI',
'middleName' => 'T',
'notice_type' => 'PHONE',
'pin' => 'Waffles125',
'postal_code' => '97209',
'profile' => 'ONLINE',
'patron_id' => '99999999998',
Expand All @@ -43,7 +44,7 @@

$addr_num = 1;
$template = 'registration_email.html.twig';
$role = 'PATRON';
$role = 'STAFF';
$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $template, 'Waffles are good');
print json_encode($response, JSON_PRETTY_PRINT) . "\n";

Expand Down
3 changes: 2 additions & 1 deletion test/register_staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'city_state' => 'Portland, OR',
'county' => '0_MULT',
'profile' => '0_MULT',
'patron_id' => '99999999999995',
'patron_id' => '99999999999997',
'email' => '[email protected]',
'firstName' => 'Bogus',
'friends_notices' => 'YES',
Expand All @@ -27,6 +27,7 @@
'library_news' => 'YES',
'middleName' => 'T',
'notice_type' => 'PHONE',
'pin' => 'Waffles125',
'postal_code' => '97209',
'street' => '925 NW Hoyt St Apt 406',
'telephone' => '215-534-6821',
Expand Down

0 comments on commit a5403c7

Please sign in to comment.