src/MailBundle/EventListener/Declaration/CoordinationHourExceededEventListener.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\MailBundle\EventListener\Declaration;
  3. use App\Entity\Declaration\Declaration;
  4. use App\Entity\Staff\Role;
  5. use App\Entity\ValidationRequest;
  6. use App\Event\Declaration\CoordinationHourExceededEvent;
  7. use App\Exception\MissingEnvVariableException;
  8. use App\MailBundle\Entity\Mail;
  9. use App\MailBundle\EventListener\MailListener;
  10. use App\MailBundle\Exception\MissingTemplateException;
  11. use App\MailBundle\Service\MailSender;
  12. use App\Repository\StaffRepository;
  13. use App\Service\Tools;
  14. use JetBrains\PhpStorm\NoReturn;
  15. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  16. use Symfony\Component\Mime\Email;
  17. use Twig\Error\LoaderError;
  18. use Twig\Error\RuntimeError;
  19. use Twig\Error\SyntaxError;
  20. use Vich\UploaderBundle\Event\Event;
  21. class CoordinationHourExceededEventListener extends DeclarationEventListener
  22. {
  23.     /**
  24.      * @throws SyntaxError
  25.      * @throws MissingTemplateException
  26.      * @throws TransportExceptionInterface
  27.      * @throws RuntimeError
  28.      * @throws LoaderError
  29.      */
  30.     #[NoReturn]
  31.     public function onCoordinationHourExceeded(CoordinationHourExceededEvent $event)
  32.     {
  33.         $data $this->getBaseTemplateData();
  34.         $establishment $event->getDeclaration()?->getEstablishmentDiploma()?->getEstablishment();
  35.         $diploma $event->getDeclaration()?->getEstablishmentDiploma()?->getDiploma();
  36.         $schoolYear $event->getDeclaration()?->getEstablishmentDiploma()?->getSchoolYear();
  37.         $data['button_url'] = $this->establishmentEditRoute $establishment->getSlug();
  38.         $data['from'] = $event?->getFrom()?->getFullName();
  39.         $data['establishment'] = $establishment?->getName();
  40.         $data['diploma'] = $diploma?->getDataOfYear($schoolYear)?->getName();
  41.         $emails = [
  42.             $this->payrollDepartmentEmail,
  43.             $event->getFrom()->getEmail(),
  44.             $this->establishmentStaffRepository->getEstablishmentDiplomaManagerAndHigher($establishment$schoolYear),
  45.         ];
  46.         $mail = new Mail(
  47.             Mail::COORDINATION_HOUR_EXCEEDED_TEMPLATE,
  48.             $emails,
  49.             $data
  50.         );
  51.         $this->mailSender->sendEmail($mail);
  52.     }
  53. }