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.

37 rindas
1.5KB

  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. ?>