Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AutomaticEmailResolver.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  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. }