src/EventListener/HolidayEventListener.php line 43

Open in your IDE?
  1. <?php
  2. // src/EventListener/HolidayEventListener.php
  3. namespace App\EventListener;
  4. use App\Event\HolidayEvent;
  5. use App\Services\GeneralService;
  6. use App\Services\NotificationService;
  7. class HolidayEventListener
  8. {
  9.     private $notificationProvider;
  10.     private $generalProvider;
  11.     public function __construct(NotificationService $notificationProviderGeneralService $generalProvider)
  12.     {
  13.         $this->notificationProvider $notificationProvider;
  14.         $this->generalProvider $generalProvider;
  15.     }
  16.     public function onRequestCreated(HolidayEvent $event)
  17.     {
  18.         $data $event->getData();
  19.         $subject "Holiday Request";
  20.         $this->sendNotification($data['recipients'], $data['msg'], $data['id']);
  21.         $this->sendEmail($data['recipients'], $data['msg'], $subject);
  22.     }
  23.     public function onRequestAccepted(HolidayEvent $event)
  24.     {
  25.         $data $event->getData();
  26.         $subject "Holiday Request";
  27.         $this->sendNotification($data['recipients'], $data['msg'], $data['id']);
  28.         $this->sendEmail($data['recipients'], $data['msg'], $subject);
  29.     }
  30.     public function onRequestRejected(HolidayEvent $event)
  31.     {
  32.         $data $event->getData();
  33.         $subject "Holiday Request";
  34.         $this->sendNotification($data['recipients'], $data['msg'], $data['id']);
  35.         $this->sendEmail($data['recipients'], $data['msg'], $subject);
  36.     }
  37.     public function onAmendmentCreated(HolidayEvent $event)
  38.     {
  39.         $data $event->getData();
  40.         $subject "Holiday Amendment";
  41.         $this->sendNotification($data['recipients'], $data['msg'], $data['id']);
  42.         $this->sendEmail($data['recipients'], $data['msg'], $subject);
  43.     }
  44.     protected function sendNotification($recipients$msg$userId)
  45.     {
  46.         foreach ($recipients as $recipient) {
  47.             $this->notificationProvider->createNotification(
  48.                 $recipient,
  49.                 $msg,
  50.                 'holidays',
  51.                 null,
  52.                 $userId
  53.             );
  54.         }
  55.     }
  56.     protected function sendEmail($recipients$msg$subject)
  57.     {
  58.         foreach ($recipients as $recipient) {
  59.             $name $this->generalProvider->getUserName($recipient);
  60.             $params = ['subject' => $subject'title' => '''greeting' => "Hi $name,"'body' => $msg'header' => '''subtitle' => ''];
  61.             $this->generalProvider->sendEmail($recipient->getEmail(), '/en/mails/oscare-generic'$params);
  62.         }
  63.     }
  64. }