|
123456789101112131415161718192021222324252627282930313233343536 |
- <?php
-
- namespace console\commands;
-
- use domain\Communication\AutomaticEmail\AutomaticEmailModule;
- use domain\Communication\Email\EmailModule;
- use domain\Producer\Producer\ProducerModule;
- use yii\console\Controller;
-
- class AutomaticEmailController extends Controller
- {
- // ./yii automatic-email/send
- public function actionSend()
- {
- $automaticEmailModule = AutomaticEmailModule::getInstance();
- $producerModule = ProducerModule::getInstance();
- $emailModule = EmailModule::getInstance();
-
- $producersArray = $producerModule->getRepository()->findProducers();
- foreach($producersArray as $producer) {
- \Yii::$app->logic->setProducerContext($producer);
- $automaticEmailsArray = $automaticEmailModule->getRepository()->findAutomaticEmails();
- foreach($automaticEmailsArray as $automaticEmail) {
- $distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail);
- if($distribution) {
- $email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution);
- $usersArray = $emailModule->getContactListResolver()->search($producer, $distribution);
- $emailModule->getBulkMailer()->sendEmail($email, $usersArray);
- echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n";
- }
- }
- }
- }
- }
-
- ?>
|