2017-08-25 10:04:19 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Setting;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class AuditNotification 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.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-05-23 11:56:56 -07:00
|
|
|
public function via()
|
2017-08-25 10:04:19 -07:00
|
|
|
{
|
|
|
|
$notifyBy = [];
|
|
|
|
if (Setting::getSettings()->slack_endpoint) {
|
|
|
|
$notifyBy[] = 'slack';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifyBy;
|
|
|
|
}
|
|
|
|
|
2020-05-23 11:56:56 -07:00
|
|
|
public function toSlack()
|
2017-08-25 10:04:19 -07:00
|
|
|
{
|
|
|
|
return (new SlackMessage)
|
|
|
|
->success()
|
2021-06-10 13:15:52 -07:00
|
|
|
->content(class_basename(get_class($this->params['item'])).' Audited')
|
2020-05-23 11:56:56 -07:00
|
|
|
->attachment(function ($attachment) {
|
2017-08-25 10:04:19 -07:00
|
|
|
$item = $this->params['item'];
|
|
|
|
$admin_user = $this->params['admin'];
|
|
|
|
$fields = [
|
2021-06-10 13:15:52 -07:00
|
|
|
'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>',
|
2017-08-25 10:04:19 -07:00
|
|
|
];
|
|
|
|
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
|
2017-08-31 21:30:38 -07:00
|
|
|
array_key_exists('location', $this->params) && $fields['Location'] = $this->params['location'];
|
2017-08-25 10:04:19 -07:00
|
|
|
|
2017-08-31 21:30:38 -07:00
|
|
|
$attachment->title($item->present()->name, $item->present()->viewUrl())
|
2017-08-25 10:04:19 -07:00
|
|
|
->fields($fields);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|