您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
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. }