選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

73 行
2.3KB

  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\PointSale\PointSale\PointSale;
  8. use domain\Producer\Producer\Producer;
  9. class AutomaticEmailManager extends AbstractManager
  10. {
  11. protected AutomaticEmailBuilder $automaticEmailBuilder;
  12. protected EmailGenerator $emailGenerator;
  13. public function loadDependencies(): void
  14. {
  15. $this->automaticEmailBuilder = $this->loadService(AutomaticEmailBuilder::class);
  16. $this->emailGenerator = $this->loadService(EmailGenerator::class);
  17. }
  18. public function createAutomaticEmail(
  19. Producer $producer,
  20. string $subject,
  21. string $message,
  22. int $day = null,
  23. PointSale $pointSale = null,
  24. int $delayBeforeDistribution = null,
  25. int $sendingDay = null,
  26. int $sendingHour = null,
  27. bool $integrateProductList = null
  28. ): AutomaticEmail
  29. {
  30. $automaticEmail = $this->automaticEmailBuilder->instanciateAutomaticEmail($producer);
  31. if($day) {
  32. $automaticEmail->setDay($day);
  33. $automaticEmail->setSendingDay(null);
  34. $automaticEmail->setDelayBeforeDistribution($delayBeforeDistribution);
  35. }
  36. else {
  37. $automaticEmail->setSendingDay($sendingDay);
  38. $automaticEmail->setDelayBeforeDistribution(null);
  39. }
  40. if($pointSale) {
  41. $automaticEmail->setPointSale($pointSale);
  42. }
  43. $automaticEmail->setSendingHour($sendingHour);
  44. $automaticEmail->setSubject($subject);
  45. $automaticEmail->setMessage($message);
  46. $automaticEmail->setIntegrateProductList($integrateProductList);
  47. $automaticEmail->save();
  48. return $automaticEmail;
  49. }
  50. public function createEmailFromAutomaticEmail(AutomaticEmail $automaticEmail, Distribution $distribution = null): Email
  51. {
  52. return $this->emailGenerator->createEmail(
  53. $automaticEmail->getSubject(),
  54. $automaticEmail->getMessage(),
  55. $automaticEmail->getIntegrateProductList(),
  56. $automaticEmail->getProducer(),
  57. $distribution,
  58. true
  59. );
  60. }
  61. }