|
|
@ -5,21 +5,23 @@ namespace App\Listeners; |
|
|
|
use App\Events\TaskUpdate; |
|
|
|
use App\Models\Task; |
|
|
|
use App\Models\User; |
|
|
|
use App\Notifications\DBNotification; |
|
|
|
use App\Notifications\FcmNotification; |
|
|
|
use App\Notifications\MailNotification; |
|
|
|
use Illuminate\Support\Facades\Notification; |
|
|
|
use App\Utilities\HelperClass\NotificationHelper; |
|
|
|
|
|
|
|
class TaskUpdateNotif |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @var NotificationHelper |
|
|
|
*/ |
|
|
|
public $helper; |
|
|
|
|
|
|
|
/** |
|
|
|
* Create the event listener. |
|
|
|
* |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function __construct() |
|
|
|
public function __construct(NotificationHelper $helper) |
|
|
|
{ |
|
|
|
//
|
|
|
|
$this->helper = $helper; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -49,18 +51,16 @@ class TaskUpdateNotif |
|
|
|
$user = User::findOrFail($payload->data->diff->assignee_id); |
|
|
|
$task = Task::findOrFail($payload->data->original->id); |
|
|
|
|
|
|
|
$notif = $this->makeNotif($payload, 'assignee', ['task' => $task->title]); |
|
|
|
|
|
|
|
$this->sendNotifications($user, $notif); |
|
|
|
$this->helper->makeNotif($payload, 'assignee', ['task' => $task->title]) |
|
|
|
->sendNotifications($user, 'critical'); |
|
|
|
} |
|
|
|
|
|
|
|
public function approverNotifHandler($payload) { |
|
|
|
$user = User::findOrFail($payload->data->diff->approver_id); |
|
|
|
$task = Task::findOrFail($payload->data->original->id); |
|
|
|
|
|
|
|
$notif = $this->makeNotif($payload, 'approver', ['task' => $task->title]); |
|
|
|
|
|
|
|
$this->sendNotifications($user, $notif); |
|
|
|
$this->helper->makeNotif($payload, 'approver', ['task' => $task->title]) |
|
|
|
->sendNotifications($user, 'critical'); |
|
|
|
} |
|
|
|
|
|
|
|
public function completedNotifHandler($payload){ |
|
|
@ -74,9 +74,8 @@ class TaskUpdateNotif |
|
|
|
|
|
|
|
$users = User::whereIn('id', $user_ids)->where('id', '!=', auth()->id())->get(); |
|
|
|
|
|
|
|
$notif = $this->makeNotif($payload, 'completed', ['task' => $task->title]); |
|
|
|
|
|
|
|
$this->sendNotifications($users, $notif); |
|
|
|
$this->helper->makeNotif($payload, 'completed', ['task' => $task->title]) |
|
|
|
->sendNotifications($users, 'critical'); |
|
|
|
} |
|
|
|
|
|
|
|
public function readyNotifHandler($payload) |
|
|
@ -90,66 +89,7 @@ class TaskUpdateNotif |
|
|
|
|
|
|
|
$users = User::whereIn('id', $user_ids)->where('id', '!=', auth()->id())->get(); |
|
|
|
|
|
|
|
$notif = $this->makeNotif($payload, 'ready', ['task' => $task->title]); |
|
|
|
|
|
|
|
$this->sendNotifications($users, $notif); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Make notification object |
|
|
|
* |
|
|
|
* @param $payload |
|
|
|
* @param null $route |
|
|
|
* @param array $options |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function makeNotif($payload, $route = null, $options = []) { |
|
|
|
$route = $route == null ? "" : $route.'.'; |
|
|
|
return [ |
|
|
|
'greeting' => $this->getMessageLine($payload, $route.'greeting'), |
|
|
|
'subject' => $this->getMessageLine($payload, $route.'subject'), |
|
|
|
'title' => $this->getMessageLine($payload, $route.'title'), |
|
|
|
'body' => $this->getMessageLine($payload, $route.'body', $options) |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Fetch message from notifications lang file |
|
|
|
* |
|
|
|
* @param $payload |
|
|
|
* @param $key |
|
|
|
* @param null $options |
|
|
|
* @return array|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Translation\Translator|string|null |
|
|
|
* |
|
|
|
*/ |
|
|
|
public function getMessageLine($payload, $key, $options = []) |
|
|
|
{ |
|
|
|
return __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.'.$key, $options); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Call notifications |
|
|
|
* |
|
|
|
* @param $users |
|
|
|
* @param $notif |
|
|
|
*/ |
|
|
|
public function sendNotifications($users, $notif) { |
|
|
|
// switch ($level) {
|
|
|
|
// case "emergency":
|
|
|
|
//// Notification::send($users, new SmsNotification($notif));
|
|
|
|
// case "critical":
|
|
|
|
// Notification::send($users, new MailNotification($notif));
|
|
|
|
// case "high":
|
|
|
|
// Notification::send($users, new DBNotification($notif));
|
|
|
|
// case "medium":
|
|
|
|
// Notification::send($users, new FcmNotification($notif));
|
|
|
|
// case "low":
|
|
|
|
//// Notification::send($users, new SocketNotification($notif));
|
|
|
|
// default:
|
|
|
|
//// Notification::send($users, new SocketNotification($notif));
|
|
|
|
// }
|
|
|
|
Notification::send($users, new MailNotification($notif)); |
|
|
|
Notification::send($users, new DBNotification($notif)); |
|
|
|
Notification::send($users, new FcmNotification($notif)); |
|
|
|
$this->helper->makeNotif($payload, 'ready', ['task' => $task->title]) |
|
|
|
->sendNotifications($users, 'critical'); |
|
|
|
} |
|
|
|
} |