From 2362cb5e5221ecae78c6aaf28bf8380f5ae20de2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 4 Nov 2024 16:32:46 -0800 Subject: [PATCH] refactor to getNotifiables --- app/Listeners/CheckoutableListener.php | 39 ++++++++++---------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 0a0c586dae..8fa96acb6a 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -61,24 +61,12 @@ class CheckoutableListener $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); } $ccEmails = array_filter($adminCcEmailsArray); - $mailable = $this->getCheckoutMailType($event, $acceptance); - - if($event->checkedOutTo instanceof Asset){ - $event->checkedOutTo->load('assignedTo'); - $notifiable = $event->checkedOutTo->assignedto?->email ?? ''; - } - else if($event->checkedOutTo instanceof Location) { - $notifiable = $event->checkedOutTo->manager?->email ?? ''; - } - else{ - $notifiable = $event->checkedOutTo->email; - } + $notifiable = $this->getNotifiables($event); if (!$event->checkedOutTo->locale){ $mailable->locale($event->checkedOutTo->locale); } - // Send email notifications try { /** @@ -156,18 +144,8 @@ class CheckoutableListener } $ccEmails = array_filter($adminCcEmailsArray); $mailable = $this->getCheckinMailType($event); + $notifiable = $this->getNotifiables($event); - - if($event->checkedOutTo instanceof Asset){ - $event->checkedOutTo->load('assignedTo'); - $notifiable = $event->checkedOutTo->assignedto?->email ?? ''; - } - else if($event->checkedOutTo instanceof Location) { - $notifiable = $event->checkedOutTo->manager?->email ?? ''; - } - else{ - $notifiable = $event->checkedOutTo->email; - } if (!$event->checkedOutTo->locale){ $mailable->locale($event->checkedOutTo->locale); } @@ -311,6 +289,19 @@ class CheckoutableListener return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note); } + private function getNotifiables($event){ + + if($event->checkedOutTo instanceof Asset){ + $event->checkedOutTo->load('assignedTo'); + return $event->checkedOutTo->assignedto?->email ?? ''; + } + else if($event->checkedOutTo instanceof Location) { + return $event->checkedOutTo->manager?->email ?? ''; + } + else{ + return $event->checkedOutTo->email; + } + } /** * Register the listeners for the subscriber.