Passed
Push — master ( dd4450...9a9614 )
by Andrey
05:55
created

CategorySearch::scenarios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace app\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * CategorySearch represents the model behind the search form of `app\models\Category`.
10
 *
11
 * @package app\models
12
 */
13
class CategorySearch extends Category
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function rules()
19
    {
20
        return [
21
            [
22
                ['id'],
23
                'integer',
24
            ],
25
            [
26
                [
27
                    'created_at',
28
                    'updated_at',
29
                ],
30
                'safe',
31
            ],
32
        ];
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function scenarios()
39
    {
40
        // bypass scenarios() implementation in the parent class
41
        return Model::scenarios();
42
    }
43
44
    /**
45
     * Creates data provider instance with search query applied
46
     *
47
     * @param array $params
48
     *
49
     * @return ActiveDataProvider
50
     */
51
    public function search($params)
52
    {
53
        $query = Category::find();
54
55
        // add conditions that should always apply here
56
57
        $dataProvider = new ActiveDataProvider([
58
            'query' => $query,
59
        ]);
60
61
        $this->load($params);
62
63
        if (!$this->validate()) {
64
            // uncomment the following line if you do not want to return any records when validation fails
65
            // $query->where('0=1');
66
            return $dataProvider;
67
        }
68
69
        // grid filtering conditions
70
        $query->andFilterWhere([
71
            'id' => $this->id,
72
            'created_at' => $this->created_at,
73
            'updated_at' => $this->updated_at,
74
        ]);
75
76
        return $dataProvider;
77
    }
78
}
79