Updates checkout notifications to use new routes for accepting
This commit is contained in:
parent
e0423418d2
commit
72b43b6526
5 changed files with 112 additions and 114 deletions
|
@ -9,69 +9,100 @@ use App\Notifications\CheckoutAccessoryNotification;
|
|||
use App\Notifications\CheckoutAssetNotification;
|
||||
use App\Notifications\CheckoutConsumableNotification;
|
||||
use App\Notifications\CheckoutLicenseNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class SendingCheckOutNotificationsListener
|
||||
{
|
||||
/**
|
||||
* Handle user login events.
|
||||
* Notify the user about the checked out consumable
|
||||
*/
|
||||
public function onConsumableCheckedOut($event) {
|
||||
/**
|
||||
* Notify the user about the checked out consumable
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
$this->sendNotification(CheckoutConsumableNotification::class, $event->logEntry);
|
||||
}
|
||||
|
||||
public function onAccessoryCheckedOut($event) {
|
||||
/**
|
||||
* Notify the user about the checked out accessory
|
||||
*/
|
||||
$this->sendNotification(CheckoutAccessoryNotification::class, $event->logEntry);
|
||||
}
|
||||
|
||||
public function onLicenseCheckedOut($event) {
|
||||
/**
|
||||
* Notify the user about the checked out license
|
||||
*/
|
||||
$this->sendNotification(CheckoutLicenseNotification::class, $event->logEntry);
|
||||
}
|
||||
|
||||
public function onAssetCheckedOut($event) {
|
||||
/**
|
||||
* Notify the user about the checked out asset
|
||||
*/
|
||||
$this->sendNotification(CheckoutAssetNotification::class, $event->logEntry);
|
||||
}
|
||||
|
||||
private function sendNotification($notificationClass, $logEntry) {
|
||||
/**
|
||||
* When the item isn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if(! $logEntry->target instanceof User) {
|
||||
if(! $event->checkedOutTo instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'log_id' => $logEntry->id,
|
||||
'item' => $logEntry->item,
|
||||
'target_type' => $logEntry->target_type,
|
||||
'admin' => $logEntry->user,
|
||||
Notification::send(
|
||||
$this->getNotifiables($event),
|
||||
new CheckoutConsumableNotification($event->consumable, $event->checkedOutTo, $event->checkedOutBy, $event->note)
|
||||
);
|
||||
}
|
||||
|
||||
'target' => $logEntry->target,
|
||||
'note' => $logEntry->note,
|
||||
'settings' => Setting::getSettings(),
|
||||
];
|
||||
/**
|
||||
* Notify the user about the checked out accessory
|
||||
*/
|
||||
public function onAccessoryCheckedOut($event) {
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if(! $event->checkedOutTo instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
$logEntry->target->notify(new $notificationClass($params));
|
||||
Notification::send(
|
||||
$this->getNotifiables($event),
|
||||
new CheckoutAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedOutBy, $event->note)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the user about the checked out license
|
||||
*/
|
||||
public function onLicenseCheckedOut($event) {
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if(! $event->checkedOutTo instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::send(
|
||||
$this->getNotifiables($event),
|
||||
new CheckoutLicenseNotification($event->license, $event->checkedOutTo, $event->checkedOutBy, $event->note)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the user about the checked out asset
|
||||
*/
|
||||
public function onAssetCheckedOut($event) {
|
||||
/**
|
||||
* When the item wasn't checked out to a user, we can't send notifications
|
||||
*/
|
||||
if(! $event->checkedOutTo instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::send(
|
||||
$this->getNotifiables($event),
|
||||
new CheckoutAssetNotification($event->asset, $event->checkedOutTo, $event->checkedOutBy, $event->note)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entities to be notified of the passed event
|
||||
*
|
||||
* @param Event $event
|
||||
* @return Collection
|
||||
*/
|
||||
private function getNotifiables($event) {
|
||||
$notifiables = collect();
|
||||
|
||||
/**
|
||||
* Notify the user who checked out the item
|
||||
*/
|
||||
$notifiables->push($event->checkedOutTo);
|
||||
|
||||
/**
|
||||
* Notify Admin users if the settings is activated
|
||||
*/
|
||||
if (Setting::getSettings()->admin_cc_email != '') {
|
||||
$recipient = new AdminRecipient();
|
||||
|
||||
$recipient->notify(new $notificationClass($params));
|
||||
$notifiables->push(new AdminRecipient());
|
||||
}
|
||||
|
||||
return $notifiables;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Setting;
|
||||
use App\Models\SnipeModel;
|
||||
use App\Models\User;
|
||||
|
@ -15,33 +16,20 @@ use Illuminate\Support\Facades\Mail;
|
|||
class CheckoutAccessoryNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct($params)
|
||||
public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->admin = $params['admin'];
|
||||
$this->log_id = $params['log_id'];
|
||||
$this->note = '';
|
||||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
$this->target_type = $params['target_type'];
|
||||
$this->settings = $params['settings'];
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
|
||||
$this->item = $accessory;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
$this->acceptance = $acceptance;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
|
||||
}
|
||||
|
||||
|
@ -140,7 +128,7 @@ class CheckoutAccessoryNotification extends Notification
|
|||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
|
||||
'accept_url' => route('account.accept.item', ['accessory', $this->item->id]),
|
||||
])
|
||||
->subject(trans('mail.Confirm_accessory_delivery'));
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
@ -13,31 +14,24 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
class CheckoutAssetNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct($params)
|
||||
public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $note)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->admin = $params['admin'];
|
||||
$this->log_id = $params['log_id'];
|
||||
$this->note = '';
|
||||
|
||||
$this->item = $asset;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
|
||||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
$this->target_type = $params['target_type'];
|
||||
$this->settings = $params['settings'];
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
|
||||
if ($this->item->last_checkout) {
|
||||
$this->last_checkout = \App\Helpers\Helper::getFormattedDateObject($this->item->last_checkout, 'date',
|
||||
|
@ -151,12 +145,11 @@ class CheckoutAssetNotification extends Notification
|
|||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'log_id' => $this->note,
|
||||
'target' => $this->target,
|
||||
'fields' => $fields,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
|
||||
'accept_url' => route('account.accept.item', ['asset', $this->item->id]),
|
||||
'last_checkout' => $this->last_checkout,
|
||||
'expected_checkin' => $this->expected_checkin,
|
||||
])
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use App\Models\Setting;
|
||||
use App\Models\SnipeModel;
|
||||
use App\Models\User;
|
||||
|
@ -25,21 +26,15 @@ class CheckoutConsumableNotification extends Notification
|
|||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct($params)
|
||||
public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $note)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->admin = $params['admin'];
|
||||
$this->log_id = $params['log_id'];
|
||||
$this->note = '';
|
||||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
$this->target_type = $params['target_type'];
|
||||
$this->settings = $params['settings'];
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
$this->item = $consumable;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
|
||||
}
|
||||
|
||||
|
@ -131,11 +126,10 @@ class CheckoutConsumableNotification extends Notification
|
|||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'log_id' => $this->note,
|
||||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
|
||||
'accept_url' => route('account.accept.item', ['consumable', $this->item->id]),
|
||||
])
|
||||
->subject(trans('mail.Confirm_consumable_delivery'));
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\License;
|
||||
use App\Models\Setting;
|
||||
use App\Models\SnipeModel;
|
||||
use App\Models\User;
|
||||
|
@ -25,23 +26,14 @@ class CheckoutLicenseNotification extends Notification
|
|||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct($params)
|
||||
public function __construct(License $license, $checkedOutTo, User $checkedOutBy, $note)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->admin = $params['admin'];
|
||||
$this->log_id = $params['log_id'];
|
||||
$this->note = '';
|
||||
$this->target_type = $params['target_type'];
|
||||
$this->settings = $params['settings'];
|
||||
$this->target_type = $params['target_type'];
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
|
||||
|
||||
$this->item = $license;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +125,7 @@ class CheckoutLicenseNotification extends Notification
|
|||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
|
||||
'accept_url' => route('account.accept.item', ['license', $this->item->id]),
|
||||
])
|
||||
->subject(trans('mail.Confirm_license_delivery'));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue