[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule()->getAuthorizationChecker() ->isGrantedAsProducer($this->getUserCurrent()) && $this->getFeatureModule()->getChecker() ->isEnabled(Feature::ALIAS_AUTOMATIC_EMAIL); } ] ], ], ]; } public function actionIndex() { return $this->render('index', [ 'dataProvider' => $this->getAutomaticEmailModule()->getRepository() ->queryAutomaticEmails()->getDataProvider(20), ]); } public function actionCreate() { $automaticEmailModule = $this->getAutomaticEmailModule(); $automaticEmailModel = $automaticEmailModule->getBuilder()->instanciateAutomaticEmail($this->getProducerCurrent()); if ($automaticEmailModel->load(\Yii::$app->request->post()) && $automaticEmailModel->validate()) { $automaticEmail = $automaticEmailModule->getManager()->createAutomaticEmail( $this->getProducerCurrent(), $automaticEmailModel->getDay(), $automaticEmailModel->getDelayBeforeDistribution(), $automaticEmailModel->getSubject(), $automaticEmailModel->getMessage(), $automaticEmailModel->getIntegrateProductList() ); $this->setFlash('success', "Email automatique ajouté"); return $this->redirectAfterSave('automatic-email', $automaticEmail->getId()); } return $this->render('create', [ 'automaticEmail' => $automaticEmailModel ]); } public function actionUpdate(int $id) { $automaticEmail = $this->findAutomaticEmail($id); if ($automaticEmail->load(\Yii::$app->request->post()) && $automaticEmail->validate() && $automaticEmail->save()) { $this->setFlash('success', "Email automatique modifié"); return $this->redirectAfterSave('automatic-email', $automaticEmail->getId()); } return $this->render('update', [ 'automaticEmail' => $automaticEmail ]); } public function actionDelete(int $id): Response { $automaticEmail = $this->findAutomaticEmail($id); if($automaticEmail->delete()) { $this->setFlash('success', "Email automatique supprimé"); } return $this->redirect('index'); } protected function findAutomaticEmail($id): AutomaticEmail { if (($automaticEmail = $this->getAutomaticEmailModule()->getRepository()->findOneAutomaticEmailById($id)) !== null) { return $automaticEmail; } else { throw new NotFoundHttpException("L'email automatique n'a pas été trouvé."); } } }