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.

AutomaticEmailController.php 1.5KB

6 maanden geleden
6 maanden geleden
12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace console\commands;
  3. use domain\Communication\AutomaticEmail\AutomaticEmailModule;
  4. use domain\Communication\Email\Email;
  5. use domain\Communication\Email\EmailModule;
  6. use domain\Producer\Producer\ProducerModule;
  7. use yii\console\Controller;
  8. class AutomaticEmailController extends Controller
  9. {
  10. // ./yii automatic-email/send
  11. public function actionSend()
  12. {
  13. $automaticEmailModule = AutomaticEmailModule::getInstance();
  14. $producerModule = ProducerModule::getInstance();
  15. $emailModule = EmailModule::getInstance();
  16. $producersArray = $producerModule->getRepository()->findProducers();
  17. foreach($producersArray as $producer) {
  18. \Yii::$app->logic->setProducerContext($producer);
  19. $automaticEmailsArray = $automaticEmailModule->getRepository()->findAutomaticEmails();
  20. foreach($automaticEmailsArray as $automaticEmail) {
  21. $distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail);
  22. if($distribution) {
  23. $email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution);
  24. $usersArray = $emailModule->getContactListResolver()->search($producer, Email::TYPE_ORDER_TAKING, $distribution);
  25. $emailModule->getBulkMailer()->sendEmail($email, $usersArray);
  26. echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n";
  27. }
  28. }
  29. }
  30. }
  31. }
  32. ?>