[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsAdministrator($this->getUserCurrent()); } ] ], ], ]; } /** * Liste les tranches de prix. */ public function actionIndex() { $dataProvider = new ActiveDataProvider([ 'query' => ProducerPriceRange::find()->orderBy('range_begin ASC') ]); return $this->render('index', [ 'dataProviderProducerPriceRange' => $dataProvider, ]); } /** * Crée une tranche de prix. */ public function actionCreate() { $producerPriceRangeModule = $this->getProducerPriceRangeModule(); $producerPriceRange = $producerPriceRangeModule->instanciateProducerPriceRange(); if ($producerPriceRange->load(\Yii::$app->request->post()) && $producerPriceRangeModule->saveCreate($producerPriceRange)) { $this->setFlash('success', 'Tranche de prix créée.'); return $this->redirect(['index']); } else { return $this->render('create', [ 'model' => $producerPriceRange, ]); } } /** * Édition d'une tranche de prix. */ public function actionUpdate(int $id) { $producerPriceRangeModule = $this->getProducerPriceRangeModule(); $producerPriceRange = $this->findModel($id); if ($producerPriceRange->load(\Yii::$app->request->post()) && $producerPriceRangeModule->saveUpdate($producerPriceRange)) { $this->setFlash('success', 'Tranche de prix éditée.'); return $this->redirect(['index']); } else { return $this->render('update', [ 'model' => $producerPriceRange, ]); } } /** * Supprime une tranche de prix. */ public function actionDelete(int $id) { $producerPriceRangeModule = $this->getProducerPriceRangeModule(); $producerPriceRange = $this->findModel($id); $producerPriceRangeModule->delete($producerPriceRange); $this->setFlash('success', 'Tranche de prix supprimée.'); return $this->redirect(['producer-price-range-admin/index']); } protected function findModel($id) { $producerPriceRangeModule = $this->getProducerPriceRangeModule(); if (($producerPriceRange = $producerPriceRangeModule->findOneProducerPriceRangeById($id)) !== null) { return $producerPriceRange; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }