[ 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsProducer($this->getUserCurrent()); } ] ], ], ]; } public function actionEmail( $idPointSale = 0, $sectionSubscribers = 0, $sectionInactiveUsers = 0, $usersPointSaleLink = 0, $usersPointSaleHasOrder = 0, $idDistribution = 0) { $producerCurrent = $this->getProducerCurrent(); $userModule = $this->getUserModule(); $distributionModule = $this->getDistributionModule(); $mailForm = new MailForm(); if ($idPointSale && !$usersPointSaleLink && !$usersPointSaleHasOrder) { $usersPointSaleLink = 1; } if ($idDistribution && !$usersPointSaleLink && !$usersPointSaleHasOrder) { $usersPointSaleLink = 1; } if($idDistribution) { $users = []; $distribution = $distributionModule->getRepository()->findOneDistributionById($idDistribution); if($distribution) { $mailForm->id_distribution = $idDistribution; foreach($distribution->pointSaleDistribution as $pointSaleDistribution) { if($pointSaleDistribution->delivery) { $usersPointSaleArray = $userModule->getRepository()->queryUsersBy([ 'id_producer' => $producerCurrent->id, 'id_point_sale' => $pointSaleDistribution->id_point_sale, 'users_point_sale_link' => $usersPointSaleLink, 'users_point_sale_has_order' => $usersPointSaleHasOrder, 'newsletter' => true ])->all(); foreach($usersPointSaleArray as $user) { $users[$user['id']] = $user; } } } } } else { $users = $userModule->queryUsersBy([ 'id_producer' => GlobalParam::getCurrentProducerId(), 'id_point_sale' => $idPointSale, 'users_point_sale_link' => $usersPointSaleLink, 'users_point_sale_has_order' => $usersPointSaleHasOrder, 'subscribers' => $sectionSubscribers, 'inactive' => $sectionInactiveUsers, 'newsletter' => true ])->all(); } $usersArray = []; foreach ($users as $key => $user) { if (isset($user['email']) && strlen($user['email']) > 0) { $usersArray[] = $user['email']; } else { unset($users[$key]); } } $pointsSaleArray = PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId(), 'status' => 1])->all(); $pointSale = null; if ($idPointSale) { $pointSale = PointSale::findOne(['id' => $idPointSale]); } if ($mailForm->load(\Yii::$app->request->post()) && $mailForm->validate()) { $mailForm->sendEmail($users); $this->setFlash('success', 'Votre email a bien été envoyé.'); // @TODO : traiter les erreurs /*if ($responseSendMail->success()) { $this->setFlash('success', 'Votre email a bien été envoyé.'); } else { $bodyResponseSendMail = $responseSendMail->getBody(); $emailsErrorArray = []; if (isset($bodyResponseSendMail['Messages'])) { foreach ($bodyResponseSendMail['Messages'] as $message) { if ($message['Status'] != 'success') { $emailsErrorArray[] = $message['Errors'][0]['ErrorMessage']; } } } $messageError = 'Un problème est survenu lors de l\'envoi de votre email.'; if (count($emailsErrorArray) > 0) { $messageError .= '
Problème détecté : ' . implode(',', $emailsErrorArray); } $this->setFlash('error', $messageError); }*/ return $this->redirect(['email', 'idPointSale' => $idPointSale]); } $incomingDistributionsArray = $distributionModule->findDistributionsIncoming(); $incomingDistributionsDatesArray = ['0' => '--']; foreach ($incomingDistributionsArray as $distribution) { $incomingDistributionsDatesArray[$distribution->id] = strftime('%A %d %B %Y', strtotime($distribution->date)); } return $this->render('email', [ 'usersArray' => $usersArray, 'pointsSaleArray' => $pointsSaleArray, 'pointSale' => $pointSale, 'mailForm' => $mailForm, 'idPointSaleActive' => $idPointSale, 'idDistributionActive' => $idDistribution, 'incomingDistributionsArray' => $incomingDistributionsArray, 'incomingDistributionsDatesArray' => $incomingDistributionsDatesArray, 'sectionSubscribers' => $sectionSubscribers, 'sectionInactiveUsers' => $sectionInactiveUsers, 'usersPointSaleLink' => $usersPointSaleLink, 'usersPointSaleHasOrder' => $usersPointSaleHasOrder, ]); } public function actionPaper() { $producer = $this->getProducerCurrent(); return $this->render('paper', [ 'producer' => $producer, ]); } /** * Génére un PDF contenant le mode d'emploi d'utilisation de la plateforme * à destination des clients des producteurs. * * @return string */ public function actionInstructions() { $producer = $this->getProducerCurrent(); // get your HTML raw content without any layouts or scripts $content = $this->renderPartial('instructions_multi', [ 'pdf' => true, 'producer' => $producer ]); $pdf = new Pdf([ // set to use core fonts only 'mode' => Pdf::MODE_UTF8, // A4 paper format 'format' => Pdf::FORMAT_A4, // portrait orientation 'orientation' => Pdf::ORIENT_PORTRAIT, // stream to browser inline 'destination' => Pdf::DEST_BROWSER, // your html content input 'content' => $content, 'marginRight' => 0, 'marginLeft' => 0, 'marginTop' => 0, 'marginBottom' => 0, // format content from your own css file if needed or use the // enhanced bootstrap css built by Krajee for mPDF formatting //'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 'cssFile' => '@app/web/css/screen.css', // any css to be embedded if required //'cssInline' => '.kv-heading-1{font-size:18px}', // set mPDF properties on the fly //'options' => ['title' => 'Krajee Report Title'], // call mPDF methods on the fly /* 'methods' => [ 'SetHeader'=>['Commandes du '.$date_str], 'SetFooter'=>['{PAGENO}'], ] */ ]); // return the pdf output as per the destination setting return $pdf->render(); } }