Skip to content

Commit

Permalink
Added role parameter to register_patron and send_query functions
Browse files Browse the repository at this point in the history
  • Loading branch information
john-c-houser committed Feb 7, 2024
1 parent 0e563cb commit 5f4f2d2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ or evaluating data from the Symphony system.
- get_patron_checkouts($token, $patron_key, $include_fields)
- get_patron_indexes($token)
- prepare_search($terms)
- register_patron($patron, $token, $addr_num, $template, $subject)
- register_patron($patron, $token, $addr_num, $role, $template, $subject)
- reset_patron_password($token, $patron_id, $url, $email)
- search_authenticate($token, $index, $search, $password)
- search_bib($token, $index, $value, $params)
Expand Down
1 change: 1 addition & 0 deletions libilsws.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ smtp:
smtp_fromname: 'SENDER NAME'
smtp_replyto: '[email protected]'
smtp_allowhtml: true
smtp_default_subject: 'Welcome to Multnomah County library'
# SirsiDynix Symphony parameters. For the most part, these must match values you have configured in
# your Symphony system.
symphony:
Expand Down
39 changes: 23 additions & 16 deletions src/Libilsws.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,18 @@ public function send_get ($url = null, $token = null, $params = null)
* @return object $response Associative array containing the response from ILSWS
*/

public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $header = '')
public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'STAFF', $header = '')
{
$this->validate('url', $url, 'u');
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('query_type', $query_type, 'v:POST|PUT|DELETE');
$this->validate('header', $header, 's:40');
$this->validate('role', $role, 'v:STAFF|PATRON');

if ( $query_json ) {
$this->validate('query_json', $query_json, 'j');
}

$role = 'STAFF';
if ( preg_match('/patron\/register/', $url) ) {
$role = 'PATRON';
} elseif ( preg_match('/patron\/changeMyPassword/', $url) ) {
$role = 'PATRON';
}

// Define a random request tracker
$req_num = rand(1, 1000000000);

Expand Down Expand Up @@ -640,7 +634,7 @@ public function transit_item ($token = null, $item_key = null, $new_library = nu
$header = "SD-Working-LibraryID: $working_library";

// Describe patron register function
$response = $this->send_query("$this->base_url/circulation/transit", $token, $json, 'POST', $header);
$response = $this->send_query("$this->base_url/circulation/transit", $token, $json, 'POST', 'STAFF', $header);

return $response;
}
Expand Down Expand Up @@ -1057,6 +1051,14 @@ 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)
{
$string = trim($string);
$string = preg_replace('#^(.*)([[:punct:]]+)$#', '$1', $string);

return trim($string);
}

/**
* Pulls a hold list for a given library
*
Expand All @@ -1073,21 +1075,25 @@ public function get_library_paging_list ($token = null, $library_key = null)
$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{title,author},callNumber,sortCallNumber},barcode,currentLocation{description}itemType}}']);
['includeFields' => 'pullList{holdRecord{holdType,status,pickupLibrary},item{call{bib{key},callNumber,sortCallNumber},barcode,currentLocation{description}itemType}}']);

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['title'] = $hold['fields']['item']['fields']['call']['fields']['bib']['fields']['title'];
$record['author'] = $hold['fields']['item']['fields']['call']['fields']['bib']['fields']['author'];
$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'];
Expand Down Expand Up @@ -2249,11 +2255,12 @@ private function create_register_json ($patron, $token = null, $addr_num = 1)
* @return object $response Associative array containing response from ILSWS
*/

public function register_patron ($patron, $token = null, $addr_num = null, $template = '', $subject = '')
public function register_patron ($patron, $token = null, $addr_num = null, $role = null, $template = '', $subject = '')
{
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('addr_num', $addr_num, 'r:#^[123]{1}$#');
$this->validate('template', $template, 'r:#^([a-zA-Z0-9]{1,40})(\.)(html|text)(\.)(twig)$#');
$this->validate('role', $role, 'v:STAFF|PATRON');

$response = [];

Expand Down Expand Up @@ -2304,7 +2311,7 @@ public function register_patron ($patron, $token = null, $addr_num = null, $temp
}

// Send initial registration (and generate email)
$response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST');
$response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST', $role);

if ( !empty($response['key']) ) {
$patron_key = $response['key'];
Expand All @@ -2329,7 +2336,7 @@ public function register_patron ($patron, $token = null, $addr_num = null, $temp

if ( $template && $this->validate('EMAIL', $patron['EMAIL'], 'e') ) {
if ( !$subject ) {
$subject = 'Welcome to Multnomah County Library';
$subject = !empty($this->config['smtp']['smtp_default_subject']) ? $this->config['smtp']['smtp_default_subject'] : '';
}
if ( ! $this->email_template($patron, $this->config['smtp']['smtp_from'], $patron['EMAIL'], $subject, $template) ) {
throw new Exception('Email to patron failed');
Expand Down
3 changes: 2 additions & 1 deletion test/register_patron.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

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

// EOF
17 changes: 9 additions & 8 deletions 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' => '99999999999993',
'patron_id' => '99999999999995',
'email' => '[email protected]',
'firstName' => 'Bogus',
'friends_notices' => 'YES',
Expand All @@ -30,19 +30,20 @@
'postal_code' => '97209',
'street' => '925 NW Hoyt St Apt 406',
'telephone' => '215-534-6821',
'sms_phone_list' => [
'phoneList' => [
'number' => '215-534-6821',
'countryCode' => 'US',
'bills' => true,
'general' => true,
'holds' => true,
'manual' => true,
'overdues' => true,
'bills' => TRUE,
'general' => TRUE,
'holds' => TRUE,
'manual' => TRUE,
'overdues' => TRUE,
],
];

$addr_num = 1;
$response = $ilsws->register_patron($patron, $token, $addr_num);
$role = 'STAFF';
$response = $ilsws->register_patron($patron, $token, $addr_num, $role);
print json_encode($response, JSON_PRETTY_PRINT) . "\n";

// EOF

0 comments on commit 5f4f2d2

Please sign in to comment.