|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\core\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use app\backend\components\BackendController; |
|
6
|
|
|
use Yii; |
|
7
|
|
|
use app\modules\core\models\ContentBlockGroup; |
|
8
|
|
|
use yii\data\ActiveDataProvider; |
|
9
|
|
|
use yii\web\NotFoundHttpException; |
|
10
|
|
|
use yii\filters\VerbFilter; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* ContentBlockGroupController implements the CRUD actions for ContentBlockGroup model. |
|
14
|
|
|
*/ |
|
15
|
|
|
class BackendChunkGroupController extends BackendController |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritdoc |
|
19
|
|
|
*/ |
|
20
|
|
|
public function behaviors() |
|
21
|
|
|
{ |
|
22
|
|
|
return [ |
|
23
|
|
|
'verbs' => [ |
|
24
|
|
|
'class' => VerbFilter::className(), |
|
25
|
|
|
'actions' => [ |
|
26
|
|
|
'delete' => ['POST'], |
|
27
|
|
|
], |
|
28
|
|
|
], |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Lists all ContentBlockGroup models. |
|
34
|
|
|
* @return mixed |
|
35
|
|
|
*/ |
|
36
|
|
|
public function actionIndex() |
|
37
|
|
|
{ |
|
38
|
|
|
$dataProvider = new ActiveDataProvider([ |
|
39
|
|
|
'query' => ContentBlockGroup::find(), |
|
40
|
|
|
]); |
|
41
|
|
|
|
|
42
|
|
|
return $this->render('index', [ |
|
43
|
|
|
'dataProvider' => $dataProvider, |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Displays a single ContentBlockGroup model. |
|
49
|
|
|
* @param integer $id |
|
50
|
|
|
* @return mixed |
|
51
|
|
|
*/ |
|
52
|
|
|
public function actionView($id) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->render('view', [ |
|
55
|
|
|
'model' => $this->findModel($id), |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Creates a new ContentBlockGroup model. |
|
61
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
*/ |
|
64
|
|
|
public function actionCreate($parent_id = 1, $returnUrl = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$model = new ContentBlockGroup(); |
|
67
|
|
|
$model->loadDefaultValues(); |
|
68
|
|
|
if (empty($model->parent_id)) { |
|
69
|
|
|
$model->parent_id = (int)$parent_id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
74
|
|
|
if ($returnUrl) { |
|
75
|
|
|
return $this->redirect($returnUrl); |
|
76
|
|
|
} |
|
77
|
|
|
return $this->redirect(['view', 'id' => $model->id]); |
|
78
|
|
|
} else { |
|
79
|
|
|
return $this->render('create', [ |
|
80
|
|
|
'model' => $model, |
|
81
|
|
|
]); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Updates an existing ContentBlockGroup model. |
|
87
|
|
|
* If update is successful, the browser will be redirected to the 'view' page. |
|
88
|
|
|
* @param integer $id |
|
89
|
|
|
* @return mixed |
|
90
|
|
|
*/ |
|
91
|
|
View Code Duplication |
public function actionUpdate($id, $returnUrl = null) |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$model = $this->findModel($id); |
|
94
|
|
|
|
|
95
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
96
|
|
|
if ($returnUrl) { |
|
97
|
|
|
return $this->redirect($returnUrl); |
|
98
|
|
|
} |
|
99
|
|
|
$this->refresh(); |
|
100
|
|
|
} else { |
|
101
|
|
|
return $this->render('update', [ |
|
102
|
|
|
'model' => $model, |
|
103
|
|
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Deletes an existing ContentBlockGroup model. |
|
109
|
|
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
|
110
|
|
|
* @param integer $id |
|
111
|
|
|
* @return mixed |
|
112
|
|
|
*/ |
|
113
|
|
View Code Duplication |
public function actionDelete($id, $returnUrl = null) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
$model = $this->findModel($id); |
|
116
|
|
|
$model->load(Yii::$app->request->post()); |
|
117
|
|
|
$model->delete(); |
|
118
|
|
|
if ($returnUrl) { |
|
119
|
|
|
return $this->redirect($returnUrl); |
|
120
|
|
|
} |
|
121
|
|
|
return $this->redirect(['/core/backend-chunk/index']); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Finds the ContentBlockGroup model based on its primary key value. |
|
126
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
|
127
|
|
|
* @param integer $id |
|
128
|
|
|
* @return ContentBlockGroup the loaded model |
|
129
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function findModel($id) |
|
132
|
|
|
{ |
|
133
|
|
|
if (($model = ContentBlockGroup::findOne($id)) !== null) { |
|
134
|
|
|
return $model; |
|
135
|
|
|
} else { |
|
136
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.