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.

AutomaticEmailController.php 1.5KB

4 meses atrás
4 meses atrás
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. ?>