Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

36 lines
1.2KB

  1. <?php
  2. namespace domain\Communication\AutomaticEmail;
  3. use domain\_\AbstractResolver;
  4. use domain\Distribution\Distribution\Distribution;
  5. use domain\Distribution\Distribution\DistributionRepository;
  6. use domain\Producer\Producer\ProducerSolver;
  7. class AutomaticEmailResolver extends AbstractResolver
  8. {
  9. protected DistributionRepository $distributionRepository;
  10. protected ProducerSolver $producerSolver;
  11. public function loadDependencies(): void
  12. {
  13. $this->distributionRepository = $this->loadService(DistributionRepository::class);
  14. $this->producerSolver = $this->loadService(ProducerSolver::class);
  15. }
  16. public function getMatchedDistribution(AutomaticEmail $automaticEmail): ?Distribution
  17. {
  18. $date = (new \DateTime('+'.$automaticEmail->getDelayBeforeDistribution().' days'));
  19. $dateFormat = $date->format('Y-m-d');
  20. $distribution = $this->distributionRepository->findOneDistribution($dateFormat);
  21. if($distribution
  22. && $distribution->active
  23. && $date->format('N') == $automaticEmail->getDay()
  24. && !$this->producerSolver->isOnLeavePeriodByDistribution($distribution)) {
  25. return $distribution;
  26. }
  27. return null;
  28. }
  29. }