refactor to getNotifiables

This commit is contained in:
Godfrey M 2024-11-04 16:32:46 -08:00
parent 93494ac554
commit 2362cb5e52

View file

@ -61,24 +61,12 @@ class CheckoutableListener
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
} }
$ccEmails = array_filter($adminCcEmailsArray); $ccEmails = array_filter($adminCcEmailsArray);
$mailable = $this->getCheckoutMailType($event, $acceptance); $mailable = $this->getCheckoutMailType($event, $acceptance);
$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){ if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale); $mailable->locale($event->checkedOutTo->locale);
} }
// Send email notifications // Send email notifications
try { try {
/** /**
@ -156,18 +144,8 @@ class CheckoutableListener
} }
$ccEmails = array_filter($adminCcEmailsArray); $ccEmails = array_filter($adminCcEmailsArray);
$mailable = $this->getCheckinMailType($event); $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){ if (!$event->checkedOutTo->locale){
$mailable->locale($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); 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. * Register the listeners for the subscriber.