1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ogheo\comments\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\base\Model; |
7
|
|
|
use yii\data\ActiveDataProvider; |
8
|
|
|
use ogheo\comments\Module as CommentsModule; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CommentsSearch represents the model behind the search form of `ogheo\comments\models\Comments`. |
12
|
|
|
* @package ogheo\comments\models |
13
|
|
|
*/ |
14
|
|
|
class CommentsSearch extends Comments |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritdoc |
18
|
|
|
*/ |
19
|
|
|
public function rules() |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
[ |
23
|
|
|
[ |
24
|
|
|
'id', |
25
|
|
|
'main_parent_id', |
26
|
|
|
'parent_id', |
27
|
|
|
'created_by', |
28
|
|
|
'updated_by', |
29
|
|
|
'created_at', |
30
|
|
|
'updated_at', |
31
|
|
|
'status' |
32
|
|
|
], |
33
|
|
|
'integer' |
34
|
|
|
], |
35
|
|
|
[['url', 'model', 'model_key', 'email', 'username', 'content', 'language', 'ip'], 'safe'], |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
|
|
public function scenarios() |
43
|
|
|
{ |
44
|
|
|
// bypass scenarios() implementation in the parent class |
45
|
|
|
return Model::scenarios(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Creates data provider instance with search query applied |
50
|
|
|
* |
51
|
|
|
* @param array $params |
52
|
|
|
* |
53
|
|
|
* @return ActiveDataProvider |
54
|
|
|
*/ |
55
|
|
|
public function search($params) |
56
|
|
|
{ |
57
|
|
|
$commentClass = CommentsModule::getInstance()->commentModelClass; |
58
|
|
|
$query = $commentClass::find(); |
59
|
|
|
|
60
|
|
|
// add conditions that should always apply here |
61
|
|
|
|
62
|
|
|
$dataProvider = new ActiveDataProvider([ |
63
|
|
|
'query' => $query, |
64
|
|
|
]); |
65
|
|
|
|
66
|
|
|
$this->load($params); |
67
|
|
|
|
68
|
|
|
if (!$this->validate()) { |
69
|
|
|
// uncomment the following line if you do not want to return any records when validation fails |
70
|
|
|
// $query->where('0=1'); |
|
|
|
|
71
|
|
|
return $dataProvider; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// grid filtering conditions |
75
|
|
|
$query->andFilterWhere([ |
76
|
|
|
'id' => $this->id, |
77
|
|
|
'main_parent_id' => $this->main_parent_id, |
78
|
|
|
'parent_id' => $this->parent_id, |
79
|
|
|
'created_by' => $this->created_by, |
80
|
|
|
'updated_by' => $this->updated_by, |
81
|
|
|
'created_at' => $this->created_at, |
82
|
|
|
'updated_at' => $this->updated_at, |
83
|
|
|
'status' => $this->status, |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
$query->andFilterWhere(['like', 'url', $this->url]) |
87
|
|
|
->andFilterWhere(['like', 'model', $this->model]) |
88
|
|
|
->andFilterWhere(['like', 'model_key', $this->model_key]) |
89
|
|
|
->andFilterWhere(['like', 'email', $this->email]) |
90
|
|
|
->andFilterWhere(['like', 'username', $this->username]) |
91
|
|
|
->andFilterWhere(['like', 'content', $this->content]) |
92
|
|
|
->andFilterWhere(['like', 'language', $this->language]) |
93
|
|
|
->andFilterWhere(['like', 'ip', $this->ip]); |
94
|
|
|
|
95
|
|
|
return $dataProvider; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.