Blame view

backend/controllers/SeoDynamicController.php 6.75 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
              $searchModel = new SeoDynamicSearch();
              $dataProvider = $searchModel->search($seo_category_id, Yii::$app->request->queryParams);
              
4428da8c   Yarik   Almost all databa...
60
61
62
63
64
65
66
67
              return $this->render(
                  'index',
                  [
                      'searchModel'  => $searchModel,
                      'dataProvider' => $dataProvider,
                      'seo_category' => $seo_category,
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
68
          }
d55d2fe0   Yarik   Multilanguage
69
70
71
72
          
          /**
           * Displays a single SeoDynamic model.
           *
21aedefe   Yarik   Another one admin...
73
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
74
75
76
77
78
79
           * @param integer $id
           *
           * @return mixed
           */
          public function actionView($seo_category_id, $id)
          {
21aedefe   Yarik   Another one admin...
80
              $seo_category = $this->findCategory($seo_category_id);
4428da8c   Yarik   Almost all databa...
81
82
83
84
85
86
87
              return $this->render(
                  'view',
                  [
                      'model'        => $this->findModel($id),
                      'seo_category' => $seo_category,
                  ]
              );
d55d2fe0   Yarik   Multilanguage
88
89
90
91
92
          }
          
          /**
           * Creates a new SeoDynamic model.
           * If creation is successful, the browser will be redirected to the 'view' page.
21aedefe   Yarik   Another one admin...
93
94
95
           *
           * @param integer $seo_category_id
           *
d55d2fe0   Yarik   Multilanguage
96
97
98
99
           * @return mixed
           */
          public function actionCreate($seo_category_id)
          {
21aedefe   Yarik   Another one admin...
100
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
101
              $model = new SeoDynamic();
72a992f5   Yarik   Import browser v1.0
102
              $model->generateLangs();
4428da8c   Yarik   Almost all databa...
103
              if ($model->load(Yii::$app->request->post())) {
72a992f5   Yarik   Import browser v1.0
104
                  $model->loadLangs(\Yii::$app->request);
d55d2fe0   Yarik   Multilanguage
105
                  $model->seo_category_id = $seo_category_id;
4428da8c   Yarik   Almost all databa...
106
107
108
109
110
111
112
                  if ($model->save() && $model->transactionStatus) {
                      return $this->redirect(
                          [
                              'index',
                              'seo_category_id' => $seo_category_id,
                          ]
                      );
d55d2fe0   Yarik   Multilanguage
113
                  }
d55d2fe0   Yarik   Multilanguage
114
              }
4428da8c   Yarik   Almost all databa...
115
116
117
118
119
120
121
122
              return $this->render(
                  'create',
                  [
                      'model'        => $model,
                      'modelLangs'   => $model->modelLangs,
                      'seo_category' => $seo_category,
                  ]
              );
d55d2fe0   Yarik   Multilanguage
123
124
125
126
127
128
          }
          
          /**
           * Updates an existing SeoDynamic model.
           * If update is successful, the browser will be redirected to the 'view' page.
           *
21aedefe   Yarik   Another one admin...
129
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
130
131
132
133
134
135
           * @param integer $id
           *
           * @return mixed
           */
          public function actionUpdate($seo_category_id, $id)
          {
21aedefe   Yarik   Another one admin...
136
              $seo_category = $this->findCategory($seo_category_id);
d55d2fe0   Yarik   Multilanguage
137
              $model = $this->findModel($id);
21aedefe   Yarik   Another one admin...
138
              $model->generateLangs();
4428da8c   Yarik   Almost all databa...
139
              if ($model->load(Yii::$app->request->post())) {
72a992f5   Yarik   Import browser v1.0
140
                  $model->loadLangs(\Yii::$app->request);
4428da8c   Yarik   Almost all databa...
141
142
143
144
145
146
147
                  if ($model->save() && $model->transactionStatus) {
                      return $this->redirect(
                          [
                              'index',
                              'seo_category_id' => $seo_category_id,
                          ]
                      );
d55d2fe0   Yarik   Multilanguage
148
149
                  }
              }
4428da8c   Yarik   Almost all databa...
150
151
152
153
154
155
156
157
              return $this->render(
                  'update',
                  [
                      'model'        => $model,
                      'modelLangs'   => $model->modelLangs,
                      'seo_category' => $seo_category,
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
158
          }
d55d2fe0   Yarik   Multilanguage
159
160
161
162
163
          
          /**
           * Deletes an existing SeoDynamic model.
           * If deletion is successful, the browser will be redirected to the 'index' page.
           *
21aedefe   Yarik   Another one admin...
164
           * @param integer $seo_category_id
d55d2fe0   Yarik   Multilanguage
165
166
167
168
169
170
171
172
173
           * @param integer $id
           *
           * @return mixed
           */
          public function actionDelete($seo_category_id, $id)
          {
              $this->findModel($id)
                   ->delete();
              
4428da8c   Yarik   Almost all databa...
174
175
176
177
178
179
              return $this->redirect(
                  [
                      'index',
                      'seo_category_id' => $seo_category_id,
                  ]
              );
d55d2fe0   Yarik   Multilanguage
180
181
182
183
184
185
186
187
188
189
190
191
192
          }
          
          /**
           * 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)
          {
4428da8c   Yarik   Almost all databa...
193
194
195
196
              if (( $model = SeoDynamic::find()
                                       ->where([ 'id' => $id ])
                                       ->with('lang')
                                       ->one() ) !== null
21aedefe   Yarik   Another one admin...
197
198
199
200
201
202
203
204
205
              ) {
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
          }
          
          protected function findCategory($id)
          {
4428da8c   Yarik   Almost all databa...
206
207
208
209
              if (( $model = SeoCategory::find()
                                        ->where([ 'id' => $id ])
                                        ->with('lang')
                                        ->one() ) !== null
21aedefe   Yarik   Another one admin...
210
              ) {
d55d2fe0   Yarik   Multilanguage
211
212
213
214
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
d8c1a2e0   Yarik   Big commit artbox
215
216
          }
      }