|
- <?php
-
- namespace console\commands;
-
- use domain\Communication\AutomaticEmail\AutomaticEmailModule;
- use domain\Communication\Email\Email;
- 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($automaticEmail->isEnabled() && $distribution) {
- $email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution);
- $usersArray = $emailModule->getContactListResolver()->search($producer, Email::TYPE_ORDER_TAKING, $distribution);
- $emailModule->getBulkMailer()->sendEmail($email, $usersArray);
- echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n";
- }
- }
- }
- }
- }
-
- ?>
|