[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsAdministrator($this->getUserCurrent()); } ] ], ], ]; } public function actionIndex() { $featureModule = $this->getFeatureModule(); $dataProviderFeatures = $featureModule->getRepository()->queryAll()->getDataProvider(100); return $this->render('index', [ 'producerCurrent' => $this->getProducerCurrent(), 'dataProviderFeatures' => $dataProviderFeatures ]); } public function actionAjaxToggleStatus($id, $status) { $featureManager = $this->getFeatureModule()->getManager(); $feature = $this->findModel($id); if($status) { $featureManager->enable($feature); $messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été activée'; } else { $featureManager->disable($feature); $messageResponse = 'La fonctionnalité "'.Html::encode($feature->name).'" a bien été désactivée'; } return Ajax::responseSuccess($messageResponse); } public function actionToggleStatusFeatureProducer(int $id, bool $status = null) { $featureManager = $this->getFeatureModule()->getManager(); $feature = $this->findModel($id); if(is_null($status)) { $featureManager->defaultForProducer($feature); } elseif($status == 0) { $featureManager->disableForProducer($feature); } elseif($status == 1) { $featureManager->enableForProducer($feature); } return $this->redirectReferer(); } public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(\Yii::$app->request->post()) && $model->save()) { $this->setFlash('success', 'Fonctionnalité modifiée.'); return $this->redirect(['index']); } else { return $this->render('update', [ 'model' => $model, ]); } } protected function findModel($id) { $featureModule = $this->getFeatureModule(); if (($feature = $featureModule->getRepository()->findOneFeatureById($id)) !== null) { return $feature; } else { throw new NotFoundHttpException('La fonctionnalité demandée est introuvable.'); } } }