Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

36 linhas
1.5KB

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