From 84a5b36cdf27d0d7caa45f9c3436ecd664e971e1 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Fri, 20 Sep 2024 17:33:04 +0000 Subject: [PATCH 1/4] Email the service desk after a request is placed --- config/vufind/config.ini | 4 ++ languages/en.ini | 4 ++ .../src/VuFind/Controller/HoldsTrait.php | 52 +++++++++++++++++++ .../root/templates/Email/request-placed.phtml | 19 +++++++ 4 files changed, 79 insertions(+) create mode 100644 themes/root/templates/Email/request-placed.phtml diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 6dc6cfa4b75..4317178250b 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -375,6 +375,10 @@ renewals_enabled = false ; if available, but not supported by all drivers) title_level_holds_mode = "disabled" +; Email submitted request notifications to and from these addresses +;holds_email_to = "no-reply@myuniversity.edu" +;holds_email_from = "no-reply@myuniversity.edu" + ; Determines how holdings are grouped in the record display, using fields from ; the item information provided by the ILS driver. ; diff --git a/languages/en.ini b/languages/en.ini index 56ec648c798..91d018c144f 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -728,6 +728,7 @@ ISBN = "ISBN" ISBN/ISSN = "ISBN/ISSN" ISSN = "ISSN" Issue = "Issue" +item_barcode = "Item Barcode" Item Description = "Item Description" Item Notes = "Notes" Item removed from favorites = "Item removed from saved items" @@ -1066,6 +1067,7 @@ password_only_numeric = "Numbers only" Passwords do not match = "Passwords do not match" past_days = "{range, plural, =1 {Yesterday} =7 {Past Week} other {Past # Days}}" patron_account_expires = "Expires" +patron_barcode = "Patron Barcode" patron_status_address_missing = "Your address is missing." patron_status_card_blocked = "This library card is blocked from borrowing." patron_status_card_expired = "Your library card has expired." @@ -1221,6 +1223,8 @@ renew_success = "Renewal Successful" renew_success_summary = "Successfully renewed {count, plural, =1 {1 item} other {# items}}." Renewed = "Renewed" Request full text = "Request full text" +request_email_item_message = "A request was placed for item: %%id%%" +request_email_subject = "Request Placed for item: %%id%%" request_in_transit = "In Transit to Pickup Location" request_place_text = "Place a Request" request_submit_text = "Submit Request" diff --git a/module/VuFind/src/VuFind/Controller/HoldsTrait.php b/module/VuFind/src/VuFind/Controller/HoldsTrait.php index ff06397c7cf..b583b4429e4 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsTrait.php +++ b/module/VuFind/src/VuFind/Controller/HoldsTrait.php @@ -195,6 +195,7 @@ public function holdAction() // Success: Go to Display Holds if (isset($results['success']) && $results['success'] == true) { + $this->emailRequestPlaced($holdDetails); $msg = [ 'html' => true, 'msg' => empty($gatheredDetails['proxiedUser']) @@ -282,4 +283,55 @@ public function holdAction() $view->setTemplate('record/hold'); return $view; } + + /** + * Email the successful request to staff as a notification. + * + * @param array $holdDetails Details about the successful hold request + * + * @return void + */ + protected function emailRequestPlaced($holdDetails) + { + $renderer = $this->getViewRenderer(); + $message = $renderer->render( + 'Email/request-placed.phtml', ['hold_details' => $holdDetails] + ); + + $config = $this->getConfig(); + $to = $this->getEmailRecipient($holdDetails); + $from = $config->Catalog->holds_email_from ?? null; + if (!$to || !$from) { + return; + } + $subject = $this->translate('request_email_subject', [ + '%%id%%' => $holdDetails['id'] ?? '', + '%%barcode%%' => $holdDetails['barcode'] ?? '', + ]); + try { + $mailer = $this->getService(\VuFind\Mailer\Mailer::class); + $mailer->send( + $to, + $from, + $subject, + $message + ); + } catch (\VuFind\Exception\Mail $e) { + return; + } + } + + /** + * Get the appropriate staff email recipient for a hold request. This falls back + * on a configured default but may be overridden to vary based on the hold details. + * + * @param array $holdDetails Details about the successful hold request + * + * @return string The email address + */ + protected function getEmailRecipient($holdDetails) + { + $config = $this->getConfig(); + return $config->Catalog->holds_email_to ?? null; + } } diff --git a/themes/root/templates/Email/request-placed.phtml b/themes/root/templates/Email/request-placed.phtml new file mode 100644 index 00000000000..3dbdc175d5e --- /dev/null +++ b/themes/root/templates/Email/request-placed.phtml @@ -0,0 +1,19 @@ + +translate('request_email_item_message', ['%%id%%' => $hold_details['id']])?> + + +----- + +translate('patron_barcode')?>: + +translate('item_barcode')?>: + +translate('Title')?>: + +translate('Call Number')?>: + +translate('Location')?>: + +translate('Comments')?>: + +translate('request_group')?>: */ ?> From 25a75312e5840ae68954f241b63f101f2a363e6c Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Fri, 20 Sep 2024 17:36:13 +0000 Subject: [PATCH 2/4] Fix styles --- module/VuFind/src/VuFind/Controller/HoldsTrait.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/Controller/HoldsTrait.php b/module/VuFind/src/VuFind/Controller/HoldsTrait.php index b583b4429e4..395927b360e 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsTrait.php +++ b/module/VuFind/src/VuFind/Controller/HoldsTrait.php @@ -295,7 +295,8 @@ protected function emailRequestPlaced($holdDetails) { $renderer = $this->getViewRenderer(); $message = $renderer->render( - 'Email/request-placed.phtml', ['hold_details' => $holdDetails] + 'Email/request-placed.phtml', + ['hold_details' => $holdDetails] ); $config = $this->getConfig(); From 7f758b6393a84725a47359c39b2cdf410f11a6c3 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Fri, 20 Sep 2024 17:38:41 +0000 Subject: [PATCH 3/4] Check whether emails are enabled before doing layout work --- module/VuFind/src/VuFind/Controller/HoldsTrait.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/HoldsTrait.php b/module/VuFind/src/VuFind/Controller/HoldsTrait.php index 395927b360e..e0ab4085774 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsTrait.php +++ b/module/VuFind/src/VuFind/Controller/HoldsTrait.php @@ -293,18 +293,19 @@ public function holdAction() */ protected function emailRequestPlaced($holdDetails) { - $renderer = $this->getViewRenderer(); - $message = $renderer->render( - 'Email/request-placed.phtml', - ['hold_details' => $holdDetails] - ); - $config = $this->getConfig(); $to = $this->getEmailRecipient($holdDetails); $from = $config->Catalog->holds_email_from ?? null; if (!$to || !$from) { return; } + + $renderer = $this->getViewRenderer(); + $message = $renderer->render( + 'Email/request-placed.phtml', + ['hold_details' => $holdDetails] + ); + $subject = $this->translate('request_email_subject', [ '%%id%%' => $holdDetails['id'] ?? '', '%%barcode%%' => $holdDetails['barcode'] ?? '', From 6efd83e39861c084f643068f1ba63b58de6ba4c5 Mon Sep 17 00:00:00 2001 From: Maccabee Levine Date: Fri, 20 Sep 2024 17:46:05 +0000 Subject: [PATCH 4/4] Fix order of en.ini --- languages/en.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/en.ini b/languages/en.ini index 91d018c144f..1b001751aff 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -728,11 +728,11 @@ ISBN = "ISBN" ISBN/ISSN = "ISBN/ISSN" ISSN = "ISSN" Issue = "Issue" -item_barcode = "Item Barcode" Item Description = "Item Description" Item Notes = "Notes" Item removed from favorites = "Item removed from saved items" Item removed from list = "Item removed from list" +item_barcode = "Item Barcode" Items = "Items" items = "items" items_added_to_bookbag = "%%count%% item(s) added to your Book Bag"