1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace modules\admin\models\search; |
4
|
|
|
|
5
|
|
|
use yii\base\Model; |
6
|
|
|
use yii\data\ActiveDataProvider; |
7
|
|
|
use modules\admin\models\User; |
8
|
|
|
use modules\admin\Module; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class UserSearch |
12
|
|
|
* @package modules\admin\models\search |
13
|
|
|
*/ |
14
|
|
|
class UserSearch extends Model |
15
|
|
|
{ |
16
|
|
|
public $id; |
17
|
|
|
public $username; |
18
|
|
|
public $email; |
19
|
|
|
public $status; |
20
|
|
|
public $last_visit; |
21
|
|
|
public $created_at; |
22
|
|
|
public $updated_at; |
23
|
|
|
public $registration_type; |
24
|
|
|
public $first_name; |
25
|
|
|
public $last_name; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritdoc |
29
|
|
|
*/ |
30
|
|
|
public function rules() |
31
|
|
|
{ |
32
|
|
|
return [ |
33
|
|
|
[['id', 'status', 'last_visit', 'created_at', 'updated_at', 'registration_type'], 'integer'], |
34
|
|
|
[['username', 'email', 'first_name', 'last_name'], 'safe'], |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function attributeLabels() |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'id' => 'ID', |
46
|
|
|
'created_at' => Module::t('users', 'Created'), |
47
|
|
|
'updated_at' => Module::t('users', 'Updated'), |
48
|
|
|
'last_visit' => Module::t('users', 'Last Visit'), |
49
|
|
|
'username' => Module::t('users', 'Username'), |
50
|
|
|
'email' => Module::t('users', 'Email'), |
51
|
|
|
'status' => Module::t('users', 'Status'), |
52
|
|
|
'first_name' => Module::t('users', 'First Name'), |
53
|
|
|
'last_name' => Module::t('users', 'Last Name'), |
54
|
|
|
'registration_type' => Module::t('users', 'Registration Type'), |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public static function getStatusesArray() |
62
|
|
|
{ |
63
|
|
|
return User::getStatusesArray(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Creates data provider instance with search query applied |
68
|
|
|
* @param $params |
69
|
|
|
* @return ActiveDataProvider |
70
|
|
|
* @throws \yii\base\InvalidConfigException |
71
|
|
|
*/ |
72
|
|
|
public function search($params) |
73
|
|
|
{ |
74
|
|
|
$query = User::find(); |
75
|
|
|
|
76
|
|
|
// add conditions that should always apply here |
77
|
|
|
|
78
|
|
|
$dataProvider = new ActiveDataProvider([ |
79
|
|
|
'query' => $query, |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
$this->load($params); |
83
|
|
|
|
84
|
|
|
if (!$this->validate()) { |
85
|
|
|
// uncomment the following line if you do not want to return any records when validation fails |
86
|
|
|
// $query->where('0=1'); |
|
|
|
|
87
|
|
|
return $dataProvider; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// grid filtering conditions |
91
|
|
|
$query->andFilterWhere([ |
92
|
|
|
'id' => $this->id, |
93
|
|
|
'status' => $this->status, |
94
|
|
|
'last_visit' => $this->last_visit, |
95
|
|
|
'created_at' => $this->created_at, |
96
|
|
|
'updated_at' => $this->updated_at, |
97
|
|
|
'registration_type' => $this->registration_type, |
98
|
|
|
]); |
99
|
|
|
|
100
|
|
|
$query->andFilterWhere(['like', 'username', $this->username]) |
101
|
|
|
->andFilterWhere(['like', 'email', $this->email]) |
102
|
|
|
->andFilterWhere(['like', 'first_name', $this->first_name]) |
103
|
|
|
->andFilterWhere(['like', 'last_name', $this->last_name]); |
104
|
|
|
|
105
|
|
|
return $dataProvider; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
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.