Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AutomaticEmailController.php 1.5KB

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