-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathCategorySearch.php
62 lines (51 loc) · 1.56 KB
/
CategorySearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Category;
class CategorySearch extends Category
{
public function rules()
{
return [
[['id_category', 'parent_id', 'is_active'], 'integer'],
[['desc_category', 'hexcolor_category'], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search($params)
{
$query = Category::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'parent_id' => SORT_ASC,
'desc_category' => SORT_ASC,
]
],
'pagination' => [
'pageSize' => 100,
],
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id_category' => $this->id_category,
'is_active' => $this->is_active,
'user_id' => Yii::$app->user->identity->id,
]);
$query->andFilterWhere(['like', 'desc_category', $this->desc_category])
->andFilterWhere(['like', 'hexcolor_category', $this->hexcolor_category]);
return $dataProvider;
}
}