|
- <?php
-
- namespace domain\Communication\AutomaticEmail;
-
- use domain\_\AbstractManager;
- use domain\Communication\Email\Email;
- use domain\Communication\Email\EmailGenerator;
- use domain\Distribution\Distribution\Distribution;
- use domain\Producer\Producer\Producer;
-
- class AutomaticEmailManager extends AbstractManager
- {
- protected AutomaticEmailBuilder $automaticEmailBuilder;
- protected EmailGenerator $emailGenerator;
-
- public function loadDependencies(): void
- {
- $this->automaticEmailBuilder = $this->loadService(AutomaticEmailBuilder::class);
- $this->emailGenerator = $this->loadService(EmailGenerator::class);
- }
-
- public function createAutomaticEmail(
- Producer $producer,
- int $day,
- int $delayBeforeDistribution,
- string $subject,
- string $message,
- bool $integrateProductList = null
- ): AutomaticEmail
- {
- $automaticEmail = $this->automaticEmailBuilder->instanciateAutomaticEmail($producer);
- $automaticEmail->setDay($day);
- $automaticEmail->setDelayBeforeDistribution($delayBeforeDistribution);
- $automaticEmail->setSubject($subject);
- $automaticEmail->setMessage($message);
- $automaticEmail->setIntegrateProductList($integrateProductList);
-
- $automaticEmail->save();
-
- return $automaticEmail;
- }
-
- public function createEmailFromAutomaticEmail(AutomaticEmail $automaticEmail, Distribution $distribution): Email
- {
- return $this->emailGenerator->createEmail(
- $automaticEmail->getSubject(),
- $automaticEmail->getMessage(),
- $automaticEmail->getIntegrateProductList(),
- $automaticEmail->getProducer(),
- $distribution
- );
- }
-
- }
|