src/MailBundle/EventListener/Declaration/ForecastedHourExceededEventListener.php line 30

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