|
- <?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\PointSale\PointSale\PointSale;
- 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,
- string $subject,
- string $message,
- int $day = null,
- PointSale $pointSale = null,
- int $delayBeforeDistribution = null,
- int $sendingDay = null,
- int $sendingHour = null,
- bool $integrateProductList = null
- ): AutomaticEmail
- {
- $automaticEmail = $this->automaticEmailBuilder->instanciateAutomaticEmail($producer);
-
- if($day) {
- $automaticEmail->setDay($day);
- $automaticEmail->setSendingDay(null);
- $automaticEmail->setDelayBeforeDistribution($delayBeforeDistribution);
- }
- else {
- $automaticEmail->setSendingDay($sendingDay);
- $automaticEmail->setDelayBeforeDistribution(null);
- }
-
- if($pointSale) {
- $automaticEmail->setPointSale($pointSale);
- }
-
- $automaticEmail->setSendingHour($sendingHour);
- $automaticEmail->setSubject($subject);
- $automaticEmail->setMessage($message);
- $automaticEmail->setIntegrateProductList($integrateProductList);
-
- $automaticEmail->save();
-
- return $automaticEmail;
- }
-
- public function createEmailFromAutomaticEmail(AutomaticEmail $automaticEmail, Distribution $distribution = null): Email
- {
- return $this->emailGenerator->createEmail(
- $automaticEmail->getSubject(),
- $automaticEmail->getMessage(),
- $automaticEmail->getIntegrateProductList(),
- $automaticEmail->getProducer(),
- $distribution,
- true
- );
- }
-
- }
|