Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Notifications;
  4.  
  5. use App\Ticket;
  6. use App\User;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Notifications\Notification;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Notifications\Messages\MailMessage;
  11. use Illuminate\Support\Facades\Storage;
  12.  
  13. class ReviewRequestSubmittedNotification extends Notification implements ShouldQueue
  14. {
  15.     use Queueable;
  16.  
  17.     public $ticket;
  18.  
  19.     /**
  20.      * Create a new notification instance.
  21.      *
  22.      * @return void
  23.      */
  24.     public function __construct(Ticket $ticket)
  25.     {
  26.         $this->ticket = $ticket;
  27.     }
  28.  
  29.     /**
  30.      * Get the notification's delivery channels.
  31.      *
  32.      * @param  mixed  $notifiable
  33.      * @return array
  34.      */
  35.     public function via($notifiable)
  36.     {
  37.         return ['mail', 'database'];
  38.     }
  39.  
  40.     /**
  41.      * Get the mail representation of the notification.
  42.      *
  43.      * @param  mixed  $notifiable
  44.      * @return \Illuminate\Notifications\Messages\MailMessage
  45.      */
  46.     public function toMail($notifiable)
  47.     {
  48.         $mail = (new MailMessage)->subject('Review Request ' . $this->ticket->ticket_number)
  49.             ->markdown('mails.' . substr($this->ticket->ticketable_type . '.review-request', 4), [
  50.                 'ticket' => $this->ticket
  51.             ]);
  52.  
  53.         if ($this->ticket->ticketable->attachments) {
  54.             foreach ($this->ticket->ticketable->attachments as $attachment) {
  55.                 $encryptedContent = Storage::get($attachment->path);
  56.                 $decryptedContent = decrypt($encryptedContent);
  57.                 $mail->attachData($decryptedContent, $attachment->filename);
  58.             }
  59.         }
  60.  
  61.         // cc to HoD PIC
  62.         $hodPic = User::find($this->ticket->department->head_of_department_id);
  63.  
  64.         if ($hodPic) {
  65.             $mail->cc($hodPic);
  66.         }
  67.  
  68.         // cc to HoD Requester
  69.         $hodRequester = User::find($this->ticket->requesterDepartment->head_of_department_id);
  70.  
  71.         if ($hodRequester) {
  72.             $mail->cc($hodRequester);
  73.         }
  74.  
  75.         return $mail;
  76.     }
  77.  
  78.     /**
  79.      * Get the array representation of the notification.
  80.      *
  81.      * @param  mixed  $notifiable
  82.      * @return array
  83.      */
  84.     public function toArray($notifiable)
  85.     {
  86.         return [
  87.             'message' => 'User ' . $this->ticket->requester->name . ' need your assistant to review something. Please click to review.',
  88.             'url' => $this->ticket->url,
  89.             'path' => $this->ticket->path
  90.         ];
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement