You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- <?php
-
- namespace domain\Communication\AutomaticEmail;
-
- use domain\_\AbstractResolver;
- use domain\Distribution\Distribution\Distribution;
- use domain\Distribution\Distribution\DistributionRepository;
- use domain\Producer\Producer\ProducerSolver;
-
- class AutomaticEmailResolver extends AbstractResolver
- {
- protected DistributionRepository $distributionRepository;
- protected ProducerSolver $producerSolver;
-
- public function loadDependencies(): void
- {
- $this->distributionRepository = $this->loadService(DistributionRepository::class);
- $this->producerSolver = $this->loadService(ProducerSolver::class);
- }
-
- public function getMatchedDistribution(AutomaticEmail $automaticEmail): ?Distribution
- {
- $date = (new \DateTime('+'.$automaticEmail->getDelayBeforeDistribution().' days'));
- $dateFormat = $date->format('Y-m-d');
- $distribution = $this->distributionRepository->findOneDistribution($dateFormat);
-
- if($distribution
- && $distribution->active
- && $date->format('N') == $automaticEmail->getDay()
- && !$this->producerSolver->isOnLeavePeriodByDistribution($distribution)) {
- return $distribution;
- }
-
- return null;
- }
- }
|