2016-12-26 15:19:04 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Setting;
|
|
|
|
use App\Models\SnipeModel;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
2017-08-31 11:14:21 -07:00
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2016-12-26 15:19:04 -08:00
|
|
|
|
|
|
|
class CheckoutNotification extends Notification
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
private $params;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @param $params
|
|
|
|
*/
|
|
|
|
public function __construct($params)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
|
|
|
$notifyBy = [];
|
2016-12-29 14:02:18 -08:00
|
|
|
if (Setting::getSettings()->slack_endpoint) {
|
2016-12-26 15:19:04 -08:00
|
|
|
$notifyBy[] = 'slack';
|
|
|
|
}
|
|
|
|
$item = $this->params['item'];
|
|
|
|
|
2017-09-29 16:09:24 -07:00
|
|
|
if (class_basename(get_class($this->params['item']))=='Asset') {
|
2017-10-11 14:42:11 -07:00
|
|
|
if ((method_exists($item, 'requireAcceptance') && ($item->requireAcceptance() == '1'))
|
|
|
|
|| (method_exists($item, 'getEula') && ($item->getEula()))
|
|
|
|
) {
|
|
|
|
$notifyBy[] = 'mail';
|
|
|
|
}
|
2017-09-29 02:00:49 -07:00
|
|
|
}
|
2016-12-26 15:19:04 -08:00
|
|
|
return $notifyBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toSlack($notifiable)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (new SlackMessage)
|
|
|
|
->success()
|
|
|
|
->content(class_basename(get_class($this->params['item'])) . " Checked Out")
|
|
|
|
->attachment(function ($attachment) use ($notifiable) {
|
|
|
|
$item = $this->params['item'];
|
|
|
|
$admin_user = $this->params['admin'];
|
|
|
|
$target = $this->params['target'];
|
|
|
|
$fields = [
|
|
|
|
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
|
|
|
|
'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>'
|
|
|
|
];
|
|
|
|
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
|
|
|
|
|
2016-12-29 14:02:18 -08:00
|
|
|
$attachment->title($item->name, $item->present()->viewUrl())
|
2016-12-26 15:19:04 -08:00
|
|
|
->fields($fields);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
2017-10-11 15:36:47 -07:00
|
|
|
if (class_basename(get_class($this->params['item']))=='Asset') {
|
2017-09-29 02:00:49 -07:00
|
|
|
|
|
|
|
//TODO: Expand for non assets.
|
|
|
|
$item = $this->params['item'];
|
|
|
|
$admin_user = $this->params['admin'];
|
|
|
|
$target = $this->params['target'];
|
|
|
|
$data = [
|
|
|
|
'eula' => method_exists($item, 'getEula') ? $item->getEula() : '',
|
|
|
|
'first_name' => $target->present()->fullName(),
|
|
|
|
'item_name' => $item->present()->name(),
|
|
|
|
'checkout_date' => $item->last_checkout,
|
|
|
|
'expected_checkin' => $item->expected_checkin,
|
|
|
|
'item_tag' => $item->asset_tag,
|
|
|
|
'note' => $this->params['note'],
|
|
|
|
'item_serial' => $item->serial,
|
|
|
|
'require_acceptance' => method_exists($item, 'requireAcceptance') ? $item->requireAcceptance() : '',
|
|
|
|
'log_id' => $this->params['log_id'],
|
|
|
|
];
|
|
|
|
|
2017-10-11 15:36:47 -07:00
|
|
|
if ((method_exists($item, 'requireAcceptance') && ($item->requireAcceptance() == '1'))
|
|
|
|
|| (method_exists($item, 'getEula') && ($item->getEula()))
|
|
|
|
) {
|
|
|
|
return (new MailMessage)
|
|
|
|
->view('emails.accept-asset', $data)
|
|
|
|
->subject(trans('mail.Confirm_asset_delivery'));
|
|
|
|
}
|
|
|
|
}
|
2017-09-29 02:00:49 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-26 15:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($notifiable)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|