src/EventSubscriber/EmailSubscriber.php line 187
use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Messenger\Exception\ExceptionInterface;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;readonly class EmailSubscriber implements EventSubscriberInterface{public function __construct(private EmailSender $emailSender,private ReviewHelper $reviewHelper,private EntityManagerInterface $entityManager,private NotificationEmailSender $notificationEmailSender,private UrlGeneratorInterface $urlGenerator) {}/*** @return array*/public static function getSubscribedEvents(): array{return [AppEvents::EMPLOYEE_CREATED => 'onNewEmployeeCreated',AppEvents::USER_RESET_PASSWORD => 'onUserResetPassword',AppEvents::USER_REGISTRATION_APPROVED => 'onUserRegistrationApproved',AppEvents::REVIEW_NOTIFY => 'onNotifyReview',AppEvents::REVIEW_NOTIFY_DENIED => 'onNotifyReviewDenied',AppEvents::UPDATE_USER_PASSWORD => 'onUpdateUserPassword',AppEvents::NOTIFIED_USERS_FOR_UPDATE_PASSWORD => 'onNotifiedUsersForUpdatePassword',];}public function onUserResetPassword(UserResetPasswordEvent $event): void{$user = $event->getUser();$notificationType = $event->getType();$emailNotification = $this->getNotificationType($notificationType);$parameters = [];$parameters["##userName##"] = $user->getFullname();$parameters["##userMail##"] = $user->getEmail();$parameters["##resetPasswordLink##"] = $_ENV['MAIN_URL'].$this->urlGenerator->generate('app_change_password', ['code' => $user->getForgetPasswordCode()]);$this->notificationEmailSender->sendNotificationMail($emailNotification, $user, $parameters);}public function onNewEmployeeCreated(EmployeeCreatedEvent $event): void{$user = $event->getUser();$notificationType = $event->getType();$emailNotification = $this->getNotificationType($notificationType);$parameters = [];$parameters["##userFullName##"] = $user->getFullname();$parameters["##loginLink##"] = $_ENV['BASE_URL'].$this->urlGenerator->generate('app_login');$this->notificationEmailSender->sendNotificationMail($emailNotification, $user, $parameters);}/*** @param UserEvent $event*/public function onUserRegistrationApproved(UserEvent $event): void{$user = $event->getUser();$notificationType = $event->getType();$emailNotification = $this->getNotificationType($notificationType);$parameters = [];$parameters["##baseURL##"] = $_ENV['BASE_URL'];$this->notificationEmailSender->sendNotificationMail($emailNotification, $user, $parameters);}public function onNotifyReview(NotifyReviewEvent $event): void{// this one remains$review = $event->getReview();/** @var User $user */$user = $review->getReviewCreator();if ($user) {$changes = $this->reviewHelper->getChangeSetValues($event->getReview(), $event->getChangeSet());$reviewType = $this->reviewHelper->getReviewType($review);if ($reviewType && strpos($reviewType, 'Edition') !== false && !$changes) {return;}$viewName = 'Email/reviewNotify.html.twig';$parameters = ['user' => $user,'review' => $review,'reviewType' => $reviewType,'changes' => $changes];$subject = 'Munireg - Review Updated';$this->emailSender->sendEmail($viewName, $parameters, $subject, $user->getEmail());}}/*** @param NotifyReviewEvent $event* @throws ExceptionInterface*/public function onNotifyReviewDenied(NotifyReviewEvent $event): void{$review = $event->getReview();$reason = $event->getReason();/** @var User $user */$user = $review->getReviewCreator();$parameters = ['##reason##' => $reason];if ($review instanceof RegistrationFormReview || $review instanceof RenewalFormReview || $review instanceof DeregistrationFormReview || $review instanceof InspectionFormReview) {$property = $review->getProperty();$address = $property->getAddress() . ', ' . $property->getCity() . ', ' . $property->getState() . ', ' . $property->getZipCode();$parameters['##address##'] = 'Property Address: ' . $address;}if ($user) {$notificationType = $event->getType();$emailNotification = $this->getNotificationType($notificationType);$this->notificationEmailSender->sendNotificationMail($emailNotification, $user, $parameters);}}public function onUpdateUserPassword(UpdateUserPasswordEvent $event): void{$this->sendPasswordUpdateNotification($event);}public function onNotifiedUsersForUpdatePassword(NotifiedForUpdateUserPasswordEvent $event): void{$this->sendPasswordUpdateNotification($event);}public function getNotificationType(string $notificationType){return $this->entityManager->getRepository(EmailNotifications::class)->findOneBy(['notificationType' => $notificationType]);}private function sendPasswordUpdateNotification($event): void{$user = $event->getUser();$notificationType = $event->getType();$emailNotification = $this->getNotificationType($notificationType);$parameters = [];$parameters["##userName##"] = $user->getFullname();$parameters["##userMail##"] = $user->getEmail();$parameters["##resetPasswordLink##"] = $_ENV['MAIN_URL'].$this->urlGenerator->generate('app_update_user_password', ['code' => $user->getForgetPasswordCode()]);$this->notificationEmailSender->sendNotificationMail($emailNotification, $user, $parameters);}}