LanguageSearch::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.9666
1
<?php
2
3
namespace Itstructure\AdminModule\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * LanguageSearch represents the model behind the search form about `Itstructure\AdminModule\models\Language`.
10
 */
11
class LanguageSearch extends Language
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [
20
                [
21
                    'id',
22
                    'default',
23
                ],
24
                'integer',
25
            ],
26
            [
27
                [
28
                    'shortName',
29
                    'name',
30
                    'created_at',
31
                    'updated_at',
32
                ],
33
                'safe',
34
            ],
35
        ];
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function scenarios()
42
    {
43
        return Model::scenarios();
44
    }
45
46
    /**
47
     * Creates data provider instance with search query applied
48
     *
49
     * @param array $params
50
     *
51
     * @return ActiveDataProvider
52
     */
53
    public function search($params)
54
    {
55
        $query = Language::find();
56
57
        $dataProvider = new ActiveDataProvider([
58
            'query' => $query,
59
        ]);
60
61
        $this->load($params);
62
63
        if (!$this->validate()) {
64
            return $dataProvider;
65
        }
66
67
        $query->andFilterWhere([
68
            'id' => $this->id,
69
            'default' => $this->default,
70
            'created_at' => $this->created_at,
71
            'updated_at' => $this->updated_at,
72
        ]);
73
74
        $query
75
            ->andFilterWhere(['like', 'shortName', $this->shortName])
76
            ->andFilterWhere(['like', 'name', $this->name]);
77
78
        return $dataProvider;
79
    }
80
}
81