src/Api/EventSubscriber/UserEventSubscriber.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Api\EventSubscriber;
  3. use App\Api\Event\UserEventStatusChangedEvent;
  4. use App\Entity\Email\UseCase;
  5. use App\Entity\User\User;
  6. use App\Notification\MailerService;
  7. use App\Notification\Template;
  8. use App\Notification\TemplateReplaceTag;
  9. use App\Notification\VCalendarGenerator;
  10. use App\Repository\Email\TemplateEmailRepository;
  11. use App\Repository\Email\UseCaseRepository;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  16. use Symfony\Component\HttpKernel\Exception\HttpException;
  17. use Symfony\Component\HttpKernel\KernelEvents;
  18. class UserEventSubscriber implements EventSubscriberInterface
  19. {
  20.     public function __construct(
  21.         private Template $template,
  22.         private TemplateReplaceTag $templateReplaceTag,
  23.         private VCalendarGenerator $vCalendarGenerator,
  24.         private MailerService $mailerService
  25.     )
  26.     {
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             UserEventStatusChangedEvent::class => 'onStatusChanged',
  32.         ];
  33.     }
  34.     public function onStatusChanged(UserEventStatusChangedEvent $userEventStatusChangedEvent)
  35.     {
  36.         $userEvent $userEventStatusChangedEvent->getUserEvent();
  37.         /** @var User $user */
  38.         $user $userEvent->getUser();
  39.         $event $userEvent->getEvent();
  40.         $findTemplate $this->template->find(UseCase::INSCRIPTION_EVENT, [
  41.             'eventType' => $event->getEventType(),
  42.             'eventProfile' => $userEvent->getProfile(),
  43.             'statusUserEvent' => $userEvent->getStatus()
  44.         ]);
  45.         if (!$findTemplate) {
  46.             return;
  47.         }
  48.         $icsAttachments  = [];
  49.         if ($userEventStatusChangedEvent->getGenerateICS()) {
  50.             $icsAttachments[$event->getTitle()] = $this->vCalendarGenerator->render($userEvent);
  51.         }
  52.         $templateData $this->templateReplaceTag->replace($findTemplate$userEvent->getUser(), $userEvent->getEvent(), $userEvent->getProfile());
  53.         $this->mailerService->sendMail($templateData['subject'], $templateData['body'], $templateData['recipents'], nullnull$icsAttachments);
  54.         // if ($user->isEmailNotificationEnabled()) {
  55.         //    // si envoie de mail activĂ©            
  56.         // }
  57.         // if ($user->isPushNotificationEnabled()) {
  58.         //     /**@todo push notification */
  59.         // }
  60.     }
  61. }