|
- <?php
-
-
-
- namespace backend\controllers;
-
- use domain\Producer\ProducerPriceRange\ProducerPriceRange;
- use yii\data\ActiveDataProvider;
- use yii\filters\AccessControl;
- use yii\web\NotFoundHttpException;
-
-
- class ProducerPriceRangeAdminController extends BackendController
- {
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return $this->getUserModule()
- ->getAuthorizationChecker()
- ->isGrantedAsAdministrator($this->getUserCurrent());
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => ProducerPriceRange::find()->orderBy('range_begin ASC')
- ]);
-
- return $this->render('index', [
- 'dataProviderProducerPriceRange' => $dataProvider,
- ]);
- }
-
-
-
- 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,
- ]);
- }
- }
-
-
-
- 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,
- ]);
- }
- }
-
-
-
- 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.');
- }
- }
- }
|