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
|
|
|
* @property int $id ID |
15
|
|
|
* @property string $username Username |
16
|
|
|
* @property string $email Email |
17
|
|
|
* @property int|string $status Status |
18
|
|
|
* @property int $last_visit Last Visit |
19
|
|
|
* @property int $created_at Created |
20
|
|
|
* @property int $updated_at Updated |
21
|
|
|
* @property string $first_name First Name |
22
|
|
|
* @property string $last_name Last Name |
23
|
|
|
* @property int $registration_type Type Registration |
24
|
|
|
*/ |
25
|
|
|
class UserSearch extends Model |
26
|
|
|
{ |
27
|
|
|
public $id; |
28
|
|
|
public $username; |
29
|
|
|
public $email; |
30
|
|
|
public $status; |
31
|
|
|
public $last_visit; |
32
|
|
|
public $created_at; |
33
|
|
|
public $updated_at; |
34
|
|
|
public $registration_type; |
35
|
|
|
public $first_name; |
36
|
|
|
public $last_name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
|
|
public function rules() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
[['id', 'status', 'last_visit', 'created_at', 'updated_at', 'registration_type'], 'integer'], |
45
|
|
|
[['username', 'email', 'first_name', 'last_name'], 'safe'], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @inheritdoc |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function attributeLabels() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'id' => 'ID', |
57
|
|
|
'created_at' => Module::t('users', 'Created'), |
58
|
|
|
'updated_at' => Module::t('users', 'Updated'), |
59
|
|
|
'last_visit' => Module::t('users', 'Last Visit'), |
60
|
|
|
'username' => Module::t('users', 'Username'), |
61
|
|
|
'email' => Module::t('users', 'Email'), |
62
|
|
|
'status' => Module::t('users', 'Status'), |
63
|
|
|
'first_name' => Module::t('users', 'First Name'), |
64
|
|
|
'last_name' => Module::t('users', 'Last Name'), |
65
|
|
|
'registration_type' => Module::t('users', 'Registration Type'), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function getStatusesArray() |
73
|
|
|
{ |
74
|
|
|
return User::getStatusesArray(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Creates data provider instance with search query applied |
79
|
|
|
* @param $params |
80
|
|
|
* @return ActiveDataProvider |
81
|
|
|
* @throws \yii\base\InvalidConfigException |
82
|
|
|
*/ |
83
|
|
|
public function search($params) |
84
|
|
|
{ |
85
|
|
|
$query = User::find(); |
86
|
|
|
|
87
|
|
|
$dataProvider = new ActiveDataProvider([ |
88
|
|
|
'query' => $query, |
89
|
|
|
]); |
90
|
|
|
|
91
|
|
|
$this->load($params); |
92
|
|
|
|
93
|
|
|
if (!$this->validate()) { |
94
|
|
|
$query->where('0=1'); |
95
|
|
|
return $dataProvider; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->processFilter($query); |
99
|
|
|
|
100
|
|
|
return $dataProvider; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param $query \yii\db\QueryInterface |
105
|
|
|
*/ |
106
|
|
|
protected function processFilter($query) |
107
|
|
|
{ |
108
|
|
|
// grid filtering conditions |
109
|
|
|
$query->andFilterWhere([ |
110
|
|
|
'id' => $this->id, |
111
|
|
|
'status' => $this->status, |
112
|
|
|
'last_visit' => $this->last_visit, |
113
|
|
|
'created_at' => $this->created_at, |
114
|
|
|
'updated_at' => $this->updated_at, |
115
|
|
|
'registration_type' => $this->registration_type, |
116
|
|
|
]); |
117
|
|
|
|
118
|
|
|
$query->andFilterWhere(['like', 'username', $this->username]) |
119
|
|
|
->andFilterWhere(['like', 'email', $this->email]) |
120
|
|
|
->andFilterWhere(['like', 'first_name', $this->first_name]) |
121
|
|
|
->andFilterWhere(['like', 'last_name', $this->last_name]); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|