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.

75 lines
2.4 KiB

  1. <?php
  2. namespace App\Utilities\HelperClass;
  3. use App\Notifications\DBNotification;
  4. use App\Notifications\FcmNotification;
  5. use App\Notifications\MailNotification;
  6. use Illuminate\Support\Facades\Notification;
  7. class NotificationHelper
  8. {
  9. protected $notif;
  10. /**
  11. * Make notification object
  12. *
  13. * @param $payload
  14. * @param null $route
  15. * @param array $options
  16. * @return array
  17. */
  18. public function makeNotif($payload, $route = null, $options = []) {
  19. $route = $route == null ? "" : $route.'.';
  20. $this->notif = [
  21. 'greeting' => $this->getMessageLine($payload, $route.'greeting'),
  22. 'subject' => $this->getMessageLine($payload, $route.'subject'),
  23. 'title' => $this->getMessageLine($payload, $route.'title'),
  24. 'body' => $this->getMessageLine($payload, $route.'body', $options)
  25. ];
  26. return $this;
  27. }
  28. /**
  29. * Fetch message from notifications lang file
  30. *
  31. * @param $payload
  32. * @param $key
  33. * @param null $options
  34. * @return array|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Translation\Translator|string|null
  35. *
  36. */
  37. protected function getMessageLine($payload, $key, $options = [])
  38. {
  39. return __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.'.$key, $options);
  40. }
  41. /**
  42. * Call notifications
  43. *
  44. * @param $users
  45. * @param $notif
  46. */
  47. public function sendNotifications($users, $level = null) {
  48. switch ($level) {
  49. case "emergency":
  50. // Notification::send($users, new SmsNotification($notif));
  51. case "critical":
  52. Notification::send($users, new MailNotification($notif));
  53. case "high":
  54. Notification::send($users, new DBNotification($notif));
  55. case "medium":
  56. Notification::send($users, new FcmNotification($notif));
  57. case "low":
  58. // Notification::send($users, new SocketNotification($notif));
  59. default:
  60. // Notification::send($users, new SocketNotification($notif));
  61. }
  62. // Notification::send($users, new MailNotification($this->notif));
  63. // Notification::send($users, new DBNotification($this->notif));
  64. // Notification::send($users, new FcmNotification($this->notif));
  65. }
  66. }