選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AutomaticEmailController.php 1.6KB

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($automaticEmail->isEnabled() && $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. ?>