Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

54 linhas
1.7KB

  1. <?php
  2. namespace domain\Communication\AutomaticEmail;
  3. use domain\_\AbstractManager;
  4. use domain\Communication\Email\Email;
  5. use domain\Communication\Email\EmailGenerator;
  6. use domain\Distribution\Distribution\Distribution;
  7. use domain\Producer\Producer\Producer;
  8. class AutomaticEmailManager extends AbstractManager
  9. {
  10. protected AutomaticEmailBuilder $automaticEmailBuilder;
  11. protected EmailGenerator $emailGenerator;
  12. public function loadDependencies(): void
  13. {
  14. $this->automaticEmailBuilder = $this->loadService(AutomaticEmailBuilder::class);
  15. $this->emailGenerator = $this->loadService(EmailGenerator::class);
  16. }
  17. public function createAutomaticEmail(
  18. Producer $producer,
  19. int $day,
  20. int $delayBeforeDistribution,
  21. string $subject,
  22. string $message,
  23. bool $integrateProductList = null
  24. ): AutomaticEmail
  25. {
  26. $automaticEmail = $this->automaticEmailBuilder->instanciateAutomaticEmail($producer);
  27. $automaticEmail->setDay($day);
  28. $automaticEmail->setDelayBeforeDistribution($delayBeforeDistribution);
  29. $automaticEmail->setSubject($subject);
  30. $automaticEmail->setMessage($message);
  31. $automaticEmail->setIntegrateProductList($integrateProductList);
  32. $automaticEmail->save();
  33. return $automaticEmail;
  34. }
  35. public function createEmailFromAutomaticEmail(AutomaticEmail $automaticEmail, Distribution $distribution): Email
  36. {
  37. return $this->emailGenerator->createEmail(
  38. $automaticEmail->getSubject(),
  39. $automaticEmail->getMessage(),
  40. $automaticEmail->getIntegrateProductList(),
  41. $automaticEmail->getProducer(),
  42. $distribution
  43. );
  44. }
  45. }