1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\controllers; |
4
|
|
|
|
5
|
|
|
use app\backend\actions\DeleteOne; |
6
|
|
|
use app\backend\actions\MultipleDelete; |
7
|
|
|
use app\backend\components\BackendController; |
8
|
|
|
use app\backend\events\BackendEntityEditEvent; |
9
|
|
|
use app\backend\traits\BackendRedirect; |
10
|
|
|
use app\models\DynamicContent; |
11
|
|
|
use app\models\Property; |
12
|
|
|
use app\models\PropertyGroup; |
13
|
|
|
use app\models\PropertyStaticValues; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\db\Query; |
16
|
|
|
use yii\filters\AccessControl; |
17
|
|
|
|
18
|
|
|
class DynamicContentController extends BackendController |
19
|
|
|
{ |
20
|
|
|
use BackendRedirect; |
21
|
|
|
|
22
|
|
|
const BACKEND_DYNAMIC_CONTENT_EDIT = 'backend-dynamic-content-edit'; |
23
|
|
|
const BACKEND_DYNAMIC_CONTENT_EDIT_SAVE = 'backend-dynamic-content-edit-save'; |
24
|
|
|
const BACKEND_DYNAMIC_CONTENT_EDIT_FORM = 'backend-dynamic-content-edit-form'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritdoc |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function behaviors() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'access' => [ |
33
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
34
|
|
|
'rules' => [ |
35
|
|
|
[ |
36
|
|
|
'allow' => true, |
37
|
|
|
'roles' => ['content manage'], |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
], |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function actions() |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
'remove-all' => [ |
51
|
|
|
'class' => MultipleDelete::className(), |
|
|
|
|
52
|
|
|
'modelName' => DynamicContent::className(), |
|
|
|
|
53
|
|
|
], |
54
|
|
|
'delete' => [ |
55
|
|
|
'class' => DeleteOne::className(), |
|
|
|
|
56
|
|
|
'modelName' => DynamicContent::className(), |
|
|
|
|
57
|
|
|
], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function actionIndex() |
62
|
|
|
{ |
63
|
|
|
$searchModel = new DynamicContent(); |
64
|
|
|
$dataProvider = $searchModel->search($_GET); |
65
|
|
|
|
66
|
|
|
return $this->render( |
67
|
|
|
'index', |
68
|
|
|
[ |
69
|
|
|
'dataProvider' => $dataProvider, |
70
|
|
|
'searchModel' => $searchModel, |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function actionEdit($id = null) |
76
|
|
|
{ |
77
|
|
|
$model = new DynamicContent; |
78
|
|
|
$model->loadDefaultValues(); |
79
|
|
|
|
80
|
|
|
if ($id !== null) { |
81
|
|
|
$model = DynamicContent::findOne($id); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$static_values_properties = []; |
85
|
|
|
$get = Yii::$app->request->get(); |
86
|
|
|
$post = Yii::$app->request->post(); |
87
|
|
|
if (isset($get['DynamicContent'])) { |
88
|
|
|
$post = $get; |
89
|
|
|
if (isset($get['DynamicContent']['object_id'])) { |
90
|
|
|
$model->object_id = (int)$get['DynamicContent']['object_id']; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
$property_groups_ids_for_object = (new Query)->select('id')->from(PropertyGroup::tableName())->where([])->column(); |
94
|
|
|
|
95
|
|
|
$properties = Property::find()->where( |
96
|
|
|
[ |
97
|
|
|
'has_static_values' => 1, |
98
|
|
|
'has_slugs_in_values' => 1, |
99
|
|
|
] |
100
|
|
|
)->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all(); |
101
|
|
View Code Duplication |
foreach ($properties as $prop) { |
102
|
|
|
$static_values_properties[$prop->id] = [ |
103
|
|
|
'has_static_values' => true, |
104
|
|
|
'property' => $prop, |
105
|
|
|
'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id), |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if ($model->load($post) && $model->validate()&&!isset($get['DynamicContent'])) { |
110
|
|
|
$save_result = $model->save(); |
111
|
|
|
if ($save_result) { |
112
|
|
|
$saveStateEvent = new BackendEntityEditEvent($model); |
|
|
|
|
113
|
|
|
$this->trigger(self::BACKEND_DYNAMIC_CONTENT_EDIT_SAVE, $saveStateEvent); |
114
|
|
|
return $this->redirectUser($model->id); |
115
|
|
|
} |
116
|
|
|
Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data')); |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
return $this->render( |
120
|
|
|
'dynamic-content-form', |
121
|
|
|
[ |
122
|
|
|
'model' => $model, |
123
|
|
|
'static_values_properties' => $static_values_properties, |
124
|
|
|
] |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.