TokenValidationBuilder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Mailer\Builder\Shop;
  4. use App\Entity\Access\Access;
  5. use App\Enum\Core\EmailSendingTypeEnum;
  6. use App\Service\Mailer\Builder\AbstractBuilder;
  7. use App\Service\Mailer\Builder\BuilderInterface;
  8. use App\Service\Mailer\Email;
  9. use App\Service\Mailer\Model\MailerModelInterface;
  10. use App\Service\Mailer\Model\Shop\TokenValidationModel;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. /**
  14. * Classe NewStructureTrialRequestValidationBuilder qui est chargé de construire l'Email de validation d'une demande d'essai de nouvelle structure.
  15. */
  16. class TokenValidationBuilder extends AbstractBuilder implements BuilderInterface
  17. {
  18. public function __construct(
  19. private readonly EntityManagerInterface $entityManager,
  20. private readonly string $opentalentNoReplyEmailAddress,
  21. ) {
  22. }
  23. public function support(MailerModelInterface $mailerModel): bool
  24. {
  25. return $mailerModel instanceof TokenValidationModel;
  26. }
  27. /**
  28. * @param TokenValidationModel $mailerModel
  29. */
  30. public function build(MailerModelInterface $mailerModel): ArrayCollection
  31. {
  32. $author = $this->entityManager->getRepository(Access::class)->find($mailerModel->getSenderId());
  33. $context = [
  34. 'token' => $mailerModel->getToken(),
  35. 'representativeFirstName' => $mailerModel->getRepresentativeFirstName(),
  36. 'representativeLastName' => $mailerModel->getRepresentativeLastName(),
  37. 'structureName' => $mailerModel->getStructureName(),
  38. 'validationUrl' => $mailerModel->getValidationUrl(),
  39. ];
  40. $content = $this->render('shop/token-validation', $context);
  41. $email = (new Email())
  42. ->setEmailEntity($this->buildEmailEntity('Validation de votre demande d\'essai', $author, $content))
  43. ->setContent($content)
  44. ->setFrom($this->opentalentNoReplyEmailAddress)
  45. ->setFromName('Opentalent');
  46. // Add recipient as a string (direct email address)
  47. $this->addRecipient($email, $mailerModel->getRepresentativeEmail(), EmailSendingTypeEnum::TO);
  48. return new ArrayCollection([$email]);
  49. }
  50. }