mailMailjetNotification = $mailMailjetNotification; $this->userStore = $userStore; $this->authorizationChecker = $authorizationChecker; $this->ticketSolver = $ticketSolver; } public static function getSubscribedEvents() { return [ TicketEvent::NEW_MESSAGE_EVENT => ['sendNotificationAfterNewMessage'], TicketEvent::NEW_TICKET_EVENT => ['sendNotificationAfterNewTicket'], ]; } public function sendNotificationAfterNewTicket(TicketEvent $ticketEvent) { $ticket = $ticketEvent->getTicket(); $lastMessage = $this->ticketSolver->getLastMessage($ticket); if ($ticket->getUser()) { $firstname = $ticket->getUser()->getFirstname(); $email = $ticket->getUser()->getEmail(); } else { $firstname = $ticket->getVisitorFirstname(); $email = $ticket->getVisitorEmail(); } if ($lastMessage->getAnswerByAdmin()) { // envoi email au client $this->mailMailjetNotification->send( [ MailMailjetNotification::SUBJECT => 'Vous avez reçu un nouveau message', MailMailjetNotification::TO_EMAIL => $email, MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-new-by-admin', MailMailjetNotification::CONTENT_DATA => [ 'firstname' => $firstname, 'ticket' => $ticket, ], ] ); } else { $this->mailMailjetNotification->send( [ MailMailjetNotification::SUBJECT => 'Nouvelle demande', MailMailjetNotification::TO_EMAIL => $email, MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-new', MailMailjetNotification::CONTENT_DATA => [ 'firstname' => $firstname, 'ticket' => $ticket, ], ] ); } $this->notifyUser($ticket); } public function sendNotificationAfterNewMessage(TicketEvent $ticketEvent) { $ticket = $ticketEvent->getTicket(); $lastMessage = $this->ticketSolver->getLastMessage($ticket); if ($ticket->getUser()) { $firstname = $ticket->getUser()->getFirstname(); $email = $ticket->getUser()->getEmail(); } else { $firstname = $ticket->getVisitorFirstname(); $email = $ticket->getVisitorEmail(); } if ($lastMessage->getAnswerByAdmin()) { // envoi email au client $this->mailMailjetNotification->send( [ MailMailjetNotification::SUBJECT => 'Réponse à votre demande', MailMailjetNotification::TO_EMAIL => $email, MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-response', MailMailjetNotification::CONTENT_DATA => [ 'firstname' => $firstname, 'ticket' => $ticket, ], ] ); } $this->notifyUser($ticket); } protected function notifyUser(TicketInterface $ticket): void { // notifyAdmin $usersToNotify = $this->userStore->getByTicketTypesNotification($ticket->getType()); foreach ($usersToNotify as $userToNotify) { if ($this->authorizationChecker->isGranted('ROLE_ADMIN', $userToNotify)) { $this->mailMailjetNotification->send( [ MailMailjetNotification::SUBJECT => 'Nouveau ticket sur Place du Local', MailMailjetNotification::TO_EMAIL => $userToNotify->getEmail(), MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-notification', MailMailjetNotification::CONTENT_DATA => [ 'firstname' => $userToNotify->getFirstname(), 'ticket' => $ticket, 'ticketMessage' => $ticket->getTicketMessages()[0], ], ] ); } } } }