Skip to content

Commit

Permalink
Allow no email and support setting subject for email
Browse files Browse the repository at this point in the history
  • Loading branch information
john-c-houser committed Feb 5, 2024
1 parent d4e6ecf commit 0e563cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 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)
- register_patron($patron, $token, $addr_num, $template, $subject)
- reset_patron_password($token, $patron_id, $url, $email)
- search_authenticate($token, $index, $search, $password)
- search_bib($token, $index, $value, $params)
Expand Down
20 changes: 12 additions & 8 deletions src/Libilsws.php
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,7 @@ 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 = '')
public function register_patron ($patron, $token = null, $addr_num = null, $template = '', $subject = '')
{
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('addr_num', $addr_num, 'r:#^[123]{1}$#');
Expand Down Expand Up @@ -2285,13 +2285,15 @@ public function register_patron ($patron, $token = null, $addr_num = null, $temp
];
$language = !empty($patron['language']) ? $languages[$patron['language']] : 'en';

if ( is_readable($this->config['symphony']['template_path'] . '/' . $template . '.' . $language) ) {
$template = $template . '.' . $language;
} else {
if ( is_readable($this->config['symphony']['template_path'] . '/' . $template . '.' . 'en') ) {
$template = $template . '.' . 'en';
if ( $template ) {
if ( is_readable($this->config['symphony']['template_path'] . '/' . $template . '.' . $language) ) {
$template = $template . '.' . $language;
} else {
throw new Exception("Missing or unreadable template file: $template");
if ( is_readable($this->config['symphony']['template_path'] . '/' . $template . '.' . 'en') ) {
$template = $template . '.' . 'en';
} else {
throw new Exception("Missing or unreadable template file: $template");
}
}
}

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

if ( $template && $this->validate('EMAIL', $patron['EMAIL'], 'e') ) {
$subject = 'Welcome to Multnomah County Library';
if ( !$subject ) {
$subject = 'Welcome to Multnomah County Library';
}
if ( ! $this->email_template($patron, $this->config['smtp']['smtp_from'], $patron['EMAIL'], $subject, $template) ) {
throw new Exception('Email to patron failed');
exit();
Expand Down
5 changes: 3 additions & 2 deletions test/register_patron.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
'firstName' => 'Bogus',
'friends_notices' => 'YES',
'home_library' => 'CEN',
'language' => 'ENGLISH',
'lastName' => 'Bogart',
'library_news' => 'YES',
'language' => 'SOMALI',
'middleName' => 'T',
'notice_type' => 'PHONE',
'postal_code' => '97209',
'profile' => 'ONLINE',
'patron_id' => '99999999998',
'street' => '925 NW Hoyt St Apt 406',
'telephone' => '215-534-6821',
'sms_phone' => [
Expand All @@ -42,7 +43,7 @@

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

// EOF
2 changes: 1 addition & 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' => '21168041717471',
'patron_id' => '99999999999993',
'email' => '[email protected]',
'firstName' => 'Bogus',
'friends_notices' => 'YES',
Expand Down

0 comments on commit 0e563cb

Please sign in to comment.