You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

83 lines
2.6 KiB

<?php
namespace App\Utilities\HelperClass;
use App\Notifications\DBNotification;
use App\Notifications\FcmNotification;
use App\Notifications\MailNotification;
use App\Notifications\SocketNotification;
use App\Notifications\SmsNotification;
use Illuminate\Support\Facades\Notification;
class NotificationHelper
{
protected $notif;
protected $sms_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.'.';
$this->notif = [
'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),
'business_id' => request('_business_info')['id']
];
return $this;
}
public function makeSmsNotif($template_name, $options = [])
{
$this->sms_notif = __('notification.sms.templates.'.$template_name, $options);
return $this;
}
/**
* 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
*
*/
protected 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, $level = null) {
switch ($level) {
case "emergency":
Notification::send($users, new SmsNotification($this->sms_notif, enum('sms.types.ultra_fast_send.name')));
case "critical":
Notification::send($users, new MailNotification($this->notif));
case "high":
Notification::send($users, new DBNotification($this->notif));
case "medium":
Notification::send($users, new FcmNotification($this->notif));
case "low":
// Notification::send($users, new SocketNotification($this->notif));
break;
default:
// Notification::send($users, new SocketNotification($this->notif));
}
}
}