|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\lookup\models; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\base\Model; |
|
7
|
|
|
use yii\data\ActiveDataProvider; |
|
8
|
|
|
use zacksleo\yii2\lookup\models\Lookup; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* LookupSearch represents the model behind the search form about `backend\modules\lookup\models\Lookup`. |
|
12
|
|
|
*/ |
|
13
|
|
|
class LookupSearch extends Lookup |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @inheritdoc |
|
17
|
|
|
*/ |
|
18
|
1 |
|
public function rules() |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
1 |
|
[['id', 'code', 'active', 'order', 'created_at', 'updated_at'], 'integer'], |
|
22
|
1 |
|
[['type', 'name', 'comment'], 'safe'], |
|
23
|
1 |
|
]; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritdoc |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function scenarios() |
|
30
|
|
|
{ |
|
31
|
|
|
// bypass scenarios() implementation in the parent class |
|
32
|
1 |
|
return Model::scenarios(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Creates data provider instance with search query applied |
|
37
|
|
|
* |
|
38
|
|
|
* @param array $params |
|
39
|
|
|
* |
|
40
|
|
|
* @return ActiveDataProvider |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function search($params) |
|
43
|
|
|
{ |
|
44
|
1 |
|
$query = Lookup::find(); |
|
45
|
|
|
|
|
46
|
1 |
|
$dataProvider = new ActiveDataProvider([ |
|
47
|
1 |
|
'query' => $query, |
|
48
|
1 |
|
]); |
|
49
|
|
|
|
|
50
|
1 |
|
$this->load($params); |
|
51
|
|
|
|
|
52
|
1 |
|
if (!$this->validate()) { |
|
53
|
|
|
// uncomment the following line if you do not want to return any records when validation fails |
|
54
|
|
|
// $query->where('0=1'); |
|
55
|
|
|
return $dataProvider; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
$query->andFilterWhere([ |
|
59
|
1 |
|
'id' => $this->id, |
|
60
|
1 |
|
'code' => $this->code, |
|
61
|
1 |
|
'active' => $this->active, |
|
62
|
1 |
|
'order' => $this->order, |
|
63
|
1 |
|
'created_at' => $this->created_at, |
|
64
|
1 |
|
'updated_at' => $this->updated_at, |
|
65
|
1 |
|
]); |
|
66
|
|
|
|
|
67
|
1 |
|
$query->andFilterWhere(['like', 'type', $this->type]) |
|
68
|
1 |
|
->andFilterWhere(['like', 'name', $this->name]) |
|
69
|
1 |
|
->andFilterWhere(['like', 'comment', $this->comment]); |
|
70
|
|
|
|
|
71
|
1 |
|
return $dataProvider; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|