1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\controllers; |
4
|
|
|
|
5
|
|
|
use app\backend\traits\BackendRedirect; |
6
|
|
|
use app\models\SpamChecker; |
7
|
|
|
use Yii; |
8
|
|
|
use yii\filters\AccessControl; |
9
|
|
|
use yii\web\Controller; |
10
|
|
|
use yii\web\NotFoundHttpException; |
11
|
|
|
|
12
|
|
|
class SpamCheckerController extends Controller |
13
|
|
|
{ |
14
|
|
|
use BackendRedirect; |
15
|
|
|
/** |
16
|
|
|
* @inheritdoc |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function behaviors() |
19
|
|
|
{ |
20
|
|
|
return [ |
21
|
|
|
'access' => [ |
22
|
|
|
'class' => AccessControl::className(), |
|
|
|
|
23
|
|
|
'rules' => [ |
24
|
|
|
[ |
25
|
|
|
'allow' => true, |
26
|
|
|
'roles' => ['setting manage'], |
27
|
|
|
], |
28
|
|
|
], |
29
|
|
|
], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function actionIndex() |
34
|
|
|
{ |
35
|
|
|
$searchModel = new SpamChecker; |
36
|
|
|
$params = Yii::$app->request->get(); |
37
|
|
|
$dataProvider = $searchModel->search($params); |
38
|
|
|
return $this->render( |
39
|
|
|
'index', |
40
|
|
|
[ |
41
|
|
|
'dataProvider' => $dataProvider, |
42
|
|
|
'searchModel' => $searchModel, |
43
|
|
|
] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function actionEdit($id = null) |
48
|
|
|
{ |
49
|
|
|
if ($id === null) { |
50
|
|
|
$model = new SpamChecker; |
51
|
|
|
} else { |
52
|
|
|
$model = SpamChecker::findOne($id); |
53
|
|
|
} |
54
|
|
|
if ($model === null) { |
55
|
|
|
throw new NotFoundHttpException; |
56
|
|
|
} |
57
|
|
|
$post = Yii::$app->request->post(); |
58
|
|
|
if ($model->load($post) && $model->validate()) { |
59
|
|
View Code Duplication |
if ($model->save()) { |
60
|
|
|
return $this->redirectUser($model->id); |
61
|
|
|
} else { |
62
|
|
|
Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot save data')); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
return $this->render('spam-checker-form', ['model' => $model]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function actionDelete($id) |
69
|
|
|
{ |
70
|
|
|
$model = SpamChecker::findOne($id); |
71
|
|
|
if ($model === null) { |
72
|
|
|
throw new NotFoundHttpException; |
73
|
|
|
} |
74
|
|
|
if ($model->delete()) { |
75
|
|
|
Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed')); |
76
|
|
|
} else { |
77
|
|
|
Yii::$app->session->setFlash('error', Yii::t('app', 'Object not removed')); |
78
|
|
|
} |
79
|
|
|
return $this->redirect(['index']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function actionDeleteAll() |
83
|
|
|
{ |
84
|
|
|
$items = Yii::$app->request->post('items', []); |
85
|
|
|
if (empty($items) === false) { |
86
|
|
|
SpamChecker::deleteAll(['in', 'id', $items]); |
87
|
|
|
} |
88
|
|
|
$this->render(['index']); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
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.