[ 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsAdministrator($this->getUserCurrent()); } ] ], ], ]; } public function actionIndex($section = 'producers') { $producerModule = $this->getProducerModule(); $userModule = $this->getUserModule(); if ($section == 'producers') { $producers = $producerModule->findProducersActive(); $usersArray = []; $users = []; foreach ($producers as $producer) { if (isset($producer->contact) && is_array($producer->contact)) { foreach ($producer->contact as $contact) { $usersArray[] = $contact->email; $users[] = [ 'email' => $contact->email, 'name' => $contact->name, 'lastname' => $contact->lastname, ]; } } } } elseif ($section == 'users') { $users = $userModule->findUsersByStatus(User::STATUS_ACTIVE); $usersArray = []; foreach ($users as $user) { if (isset($user['email']) && strlen($user['email'])) { $usersArray[] = $user['email']; } } } else { throw new NotFoundHttpException('Requête incorrecte.'); } $mailForm = new MailForm(); if ($mailForm->load(\Yii::$app->request->post()) && $mailForm->validate()) { $resultSendEmail = $mailForm->sendEmail($users, false); if ($resultSendEmail) { $this->setFlash('success', 'Votre email a bien été envoyé.'); } else { $this->setFlash('error', 'Un problème est survenu lors de l\'envoi de votre email.'); } $mailForm->subject = ''; $mailForm->message = ''; } return $this->render('index', [ 'section' => $section, 'usersArray' => $usersArray, 'mailForm' => $mailForm, ]); } }