Blame view

backend/controllers/SeoDynamicController.php 6.37 KB
d8c1a2e0   Yarik   Big commit artbox
1
  <?php
d55d2fe0   Yarik   Multilanguage
2
3
4
      
      namespace backend\controllers;
      
21aedefe   Yarik   Another one admin...
5
      use common\models\SeoCategory;
d55d2fe0   Yarik   Multilanguage
6
7
8
9
10
11
12
13
      use Yii;
      use common\models\SeoDynamic;
      use common\models\SeoDynamicSearch;
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
      use yii\filters\VerbFilter;
      use developeruz\db_rbac\behaviors\AccessBehavior;
      
d8c1a2e0   Yarik   Big commit artbox
14
      /**
d55d2fe0   Yarik   Multilanguage
15
       * SeoDynamicController implements the CRUD actions for SeoDynamic model.
d8c1a2e0   Yarik   Big commit artbox
16
       */
d55d2fe0   Yarik   Multilanguage
17
      class SeoDynamicController extends Controller
d8c1a2e0   Yarik   Big commit artbox
18
      {
d55d2fe0   Yarik   Multilanguage
19
20
21
22
23
24
25
26
27
28
29
          
          /**
           * @inheritdoc
           */
          public function behaviors()
          {
              return [
                  'access' => [
                      'class' => AccessBehavior::className(),
                      'rules' => [
                          'site' => [
d8c1a2e0   Yarik   Big commit artbox
30
                              [
d55d2fe0   Yarik   Multilanguage
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
                                  'actions' => [
                                      'login',
                                      'error',
                                  ],
                                  'allow'   => true,
                              ],
                          ],
                      ],
                  ],
                  'verbs'  => [
                      'class' => VerbFilter::className(),
                  
                  ],
              ];
          }
          
          /**
           * Lists all SeoDynamic models.
21aedefe   Yarik   Another one admin...
49
50
51
           *
           * @param int $seo_category_id
           *
d55d2fe0   Yarik   Multilanguage
52
53
54
55
           * @return mixed
           */
          public function actionIndex($seo_category_id)
          {
21aedefe   Yarik   Another one admin...
56
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
57
58
59
60
              $searchModel = new SeoDynamicSearch();
              $dataProvider = $searchModel->search($seo_category_id, Yii::$app->request->queryParams);
              
              return $this->render('index', [
21aedefe   Yarik   Another one admin...
61
62
63
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
                  'seo_category' => $seo_category,
d8c1a2e0   Yarik   Big commit artbox
64
65
              ]);
          }
d55d2fe0   Yarik   Multilanguage
66
67
68
69
          
          /**
           * Displays a single SeoDynamic model.
           *
21aedefe   Yarik   Another one admin...
70
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
71
72
73
74
75
76
           * @param integer $id
           *
           * @return mixed
           */
          public function actionView($seo_category_id, $id)
          {
21aedefe   Yarik   Another one admin...
77
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
78
              return $this->render('view', [
21aedefe   Yarik   Another one admin...
79
80
                  'model'        => $this->findModel($id),
                  'seo_category' => $seo_category,
d55d2fe0   Yarik   Multilanguage
81
82
83
84
85
86
              ]);
          }
          
          /**
           * Creates a new SeoDynamic model.
           * If creation is successful, the browser will be redirected to the 'view' page.
21aedefe   Yarik   Another one admin...
87
88
89
           *
           * @param integer $seo_category_id
           *
d55d2fe0   Yarik   Multilanguage
90
91
92
93
           * @return mixed
           */
          public function actionCreate($seo_category_id)
          {
21aedefe   Yarik   Another one admin...
94
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
95
              $model = new SeoDynamic();
72a992f5   Yarik   Import browser v1.0
96
              $model->generateLangs();
d55d2fe0   Yarik   Multilanguage
97
              if($model->load(Yii::$app->request->post())) {
72a992f5   Yarik   Import browser v1.0
98
                  $model->loadLangs(\Yii::$app->request);
d55d2fe0   Yarik   Multilanguage
99
                  $model->seo_category_id = $seo_category_id;
72a992f5   Yarik   Import browser v1.0
100
                  if($model->save() && $model->transactionStatus) {
d55d2fe0   Yarik   Multilanguage
101
102
                      return $this->redirect([
                          'index',
21aedefe   Yarik   Another one admin...
103
                          'seo_category_id' => $seo_category_id,
d55d2fe0   Yarik   Multilanguage
104
                      ]);
d55d2fe0   Yarik   Multilanguage
105
                  }
d55d2fe0   Yarik   Multilanguage
106
              }
72a992f5   Yarik   Import browser v1.0
107
              return $this->render('create', [
21aedefe   Yarik   Another one admin...
108
                  'model'        => $model,
8af13427   Yarik   For leha commit.
109
                  'modelLangs'  => $model->modelLangs,
21aedefe   Yarik   Another one admin...
110
                  'seo_category' => $seo_category,
72a992f5   Yarik   Import browser v1.0
111
              ]);
d55d2fe0   Yarik   Multilanguage
112
113
114
115
116
117
          }
          
          /**
           * Updates an existing SeoDynamic model.
           * If update is successful, the browser will be redirected to the 'view' page.
           *
21aedefe   Yarik   Another one admin...
118
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
119
120
121
122
123
124
           * @param integer $id
           *
           * @return mixed
           */
          public function actionUpdate($seo_category_id, $id)
          {
21aedefe   Yarik   Another one admin...
125
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
126
              $model = $this->findModel($id);
21aedefe   Yarik   Another one admin...
127
              $model->generateLangs();
72a992f5   Yarik   Import browser v1.0
128
129
130
              if($model->load(Yii::$app->request->post())) {
                  $model->loadLangs(\Yii::$app->request);
                  if($model->save() && $model->transactionStatus) {
d55d2fe0   Yarik   Multilanguage
131
132
                      return $this->redirect([
                          'index',
21aedefe   Yarik   Another one admin...
133
                          'seo_category_id' => $seo_category_id,
d55d2fe0   Yarik   Multilanguage
134
135
136
                      ]);
                  }
              }
d8c1a2e0   Yarik   Big commit artbox
137
              return $this->render('update', [
21aedefe   Yarik   Another one admin...
138
                  'model'        => $model,
8af13427   Yarik   For leha commit.
139
                  'modelLangs'  => $model->modelLangs,
21aedefe   Yarik   Another one admin...
140
                  'seo_category' => $seo_category,
d8c1a2e0   Yarik   Big commit artbox
141
142
              ]);
          }
d55d2fe0   Yarik   Multilanguage
143
144
145
146
147
          
          /**
           * Deletes an existing SeoDynamic model.
           * If deletion is successful, the browser will be redirected to the 'index' page.
           *
21aedefe   Yarik   Another one admin...
148
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
           * @param integer $id
           *
           * @return mixed
           */
          public function actionDelete($seo_category_id, $id)
          {
              $this->findModel($id)
                   ->delete();
              
              return $this->redirect([
                  'index',
                  'seo_category_id' => $seo_category_id,
              ]);
          }
          
          /**
           * Finds the SeoDynamic model based on its primary key value.
           * If the model is not found, a 404 HTTP exception will be thrown.
           *
           * @param integer $id
           *
           * @return SeoDynamic the loaded model
           * @throws NotFoundHttpException if the model cannot be found
           */
          protected function findModel($id)
          {
21aedefe   Yarik   Another one admin...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
              if(( $model = SeoDynamic::find()
                                      ->where([ 'seo_dynamic_id' => $id ])
                                      ->with('lang')
                                      ->one() ) !== NULL
              ) {
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
          }
          
          protected function findCategory($id)
          {
              if(( $model = SeoCategory::find()
                                       ->where([ 'seo_category_id' => $id ])
                                       ->with('lang')
                                       ->one() ) !== NULL
              ) {
d55d2fe0   Yarik   Multilanguage
193
194
195
196
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
d8c1a2e0   Yarik   Big commit artbox
197
198
          }
      }