|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
-
-
-
- namespace backend\controllers;
-
- use domain\Config\TaxRate\TaxRate;
- use yii\data\ActiveDataProvider;
- use yii\filters\AccessControl;
- use yii\filters\VerbFilter;
- use yii\web\NotFoundHttpException;
-
-
- class TaxRateAdminController extends BackendController
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- '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()
- {
- $dataProviderTaxRate = new ActiveDataProvider([
- 'query' => TaxRate::find()
- ]);
-
- return $this->render('index', [
- 'dataProviderTaxRate' => $dataProviderTaxRate,
- ]);
- }
-
- public function actionCreate()
- {
- $model = $this-> getTaxRateModule()->instanciateTaxRate();
-
- if ($model->load(\Yii::$app->request->post()) && $model->save()) {
- $this->setFlash('success', 'Taxe créée.');
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
-
- if ($model->load(\Yii::$app->request->post()) && $model->save()) {
- $this->setFlash('success', 'Taxe éditée.');
- return $this->redirect(['index']);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
- public function actionDelete(int $id)
- {
- $taxRateModule = $this-> getTaxRateModule();
- $taxRate = $this->findModel($id);
- $taxRateModule->delete($taxRate);
-
- $this->setFlash('success', 'Taxe supprimé');
-
- return $this->redirect(['tax-rate-admin/index']);
- }
-
- protected function findModel($id)
- {
- $taxRateModule = $this-> getTaxRateModule();
- if (($taxRate = $taxRateModule->findOneTaxRateById($id)) !== null) {
- return $taxRate;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|