|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\admin\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\filters\VerbFilter; |
|
7
|
|
|
use yii\helpers\Url; |
|
8
|
|
|
use app\components\BaseController; |
|
9
|
|
|
use app\models\News; |
|
10
|
|
|
use app\models\NewsType; |
|
11
|
|
|
use app\modules\admin\models\search\NewsSearch; |
|
12
|
|
|
|
|
13
|
|
|
class NewsController extends BaseController |
|
14
|
|
|
{ |
|
15
|
|
|
public function behaviors() |
|
16
|
|
|
{ |
|
17
|
|
|
return [ |
|
18
|
|
|
'verbs' => [ |
|
19
|
|
|
'class' => VerbFilter::className(), |
|
20
|
|
|
'actions' => [ |
|
21
|
|
|
'publish' => ['post'], |
|
22
|
|
|
'unpublish' => ['post'], |
|
23
|
|
|
'delete' => ['post'], |
|
24
|
|
|
'operations' => ['post'], |
|
25
|
|
|
'preview-upload' => ['post'], |
|
26
|
|
|
'gallery-upload' => ['post'], |
|
27
|
|
|
], |
|
28
|
|
|
], |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function actions() |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
'operations' => [ |
|
36
|
|
|
'class' => 'app\modules\admin\controllers\common\OperationsAction', |
|
37
|
|
|
'modelName' => 'app\models\News', |
|
38
|
|
|
'operations' => [ |
|
39
|
|
|
'delete' => [], |
|
40
|
|
|
'set-publish' => ['status' => News::STATUS_ACTIVE], |
|
41
|
|
|
'set-unpublish' => ['status' => News::STATUS_BLOCKED] |
|
42
|
|
|
] |
|
43
|
|
|
], |
|
44
|
|
|
'set-publish' => [ |
|
45
|
|
|
'class' => 'app\modules\admin\controllers\common\UpdateAttributesAction', |
|
46
|
|
|
'modelName' => 'app\models\News', |
|
47
|
|
|
'attributes' => ['status' => News::STATUS_ACTIVE], |
|
48
|
|
|
], |
|
49
|
|
|
'set-unpublish' => [ |
|
50
|
|
|
'class' => 'app\modules\admin\controllers\common\UpdateAttributesAction', |
|
51
|
|
|
'modelName' => 'app\models\News', |
|
52
|
|
|
'attributes' => ['status' => News::STATUS_BLOCKED], |
|
53
|
|
|
], |
|
54
|
|
|
'delete' => [ |
|
55
|
|
|
'class' => 'app\modules\admin\controllers\common\DeleteAction', |
|
56
|
|
|
'modelName' => 'app\models\News', |
|
57
|
|
|
], |
|
58
|
|
|
'text-upload' => [ |
|
59
|
|
|
'class' => 'rkit\filemanager\actions\UploadAction', |
|
60
|
|
|
'modelName' => 'app\models\News', |
|
61
|
|
|
'attribute' => 'text', |
|
62
|
|
|
'inputName' => 'file', |
|
63
|
|
|
'resultFieldPath' => 'filelink', |
|
64
|
|
|
'temporary' => false, |
|
65
|
|
|
], |
|
66
|
|
|
'preview-upload' => [ |
|
67
|
|
|
'class' => 'rkit\filemanager\actions\UploadAction', |
|
68
|
|
|
'modelName' => 'app\models\News', |
|
69
|
|
|
'attribute' => 'preview', |
|
70
|
|
|
'inputName' => 'file', |
|
71
|
|
|
], |
|
72
|
|
|
'gallery-upload' => [ |
|
73
|
|
|
'class' => 'rkit\filemanager\actions\UploadAction', |
|
74
|
|
|
'modelName' => 'app\models\News', |
|
75
|
|
|
'attribute' => 'gallery', |
|
76
|
|
|
'inputName' => 'file', |
|
77
|
|
|
'multiple' => true, |
|
78
|
|
|
'template' => Yii::getAlias('@app/modules/admin/views/shared/files/gallery/item.php'), |
|
79
|
|
|
], |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function actionIndex() |
|
84
|
|
|
{ |
|
85
|
|
|
$newsSearch = new NewsSearch(); |
|
86
|
|
|
$dataProvider = $newsSearch->search(Yii::$app->request->get()); |
|
87
|
|
|
$statuses = News::getStatuses(); |
|
88
|
|
|
|
|
89
|
|
|
return $this->render('index', [ |
|
90
|
|
|
'newsSearch' => $newsSearch, |
|
91
|
|
|
'dataProvider' => $dataProvider, |
|
92
|
|
|
'statuses' => $statuses, |
|
93
|
|
|
'types' => NewsType::find()->orderBy('title')->asArray()->all() |
|
94
|
|
|
]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function actionEdit($id = null) |
|
98
|
|
|
{ |
|
99
|
|
|
$model = new News(); |
|
100
|
|
|
|
|
101
|
|
|
if ($id) { |
|
102
|
|
|
$model = $this->loadModel($model, $id); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if (Yii::$app->request->isPost) { |
|
106
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
107
|
|
|
Yii::$app->session->setFlash('success', Yii::t('app', 'Saved successfully')); |
|
108
|
|
|
if (Yii::$app->request->isAjax) { |
|
109
|
|
|
return $this->response(['redirect' => Url::toRoute(['edit', 'id' => $model->id])]); |
|
110
|
|
|
} |
|
111
|
|
|
} else { |
|
112
|
|
|
if (Yii::$app->request->isAjax) { |
|
113
|
|
|
return $this->response(\app\helpers\Util::getValidationErrors($model)); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $this->render('edit', [ |
|
119
|
|
|
'model' => $model, |
|
120
|
|
|
'types' => NewsType::find()->orderBy('title')->asArray()->all() |
|
121
|
|
|
]); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.