SystemParamSearch::search()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace yiicod\systemparams\models;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * SystemParamSearch represents the model behind the search form about `yiicod\systemparams\models\SystemParamModel`.
10
 */
11
class SystemParamSearch extends SystemParamModel
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [['id'], 'integer'],
20
            [['param_key', 'param_value', 'description', 'validator'], 'safe'],
21
        ];
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function scenarios()
28
    {
29
        return Model::scenarios();
30
    }
31
32
    /**
33
     * Creates data provider instance with search query applied
34
     *
35
     * @param array $params
36
     *
37
     * @return ActiveDataProvider
38
     */
39
    public function search($params)
40
    {
41
        $query = SystemParamModel::find();
42
43
        $dataProvider = new ActiveDataProvider([
44
            'query' => $query,
45
        ]);
46
47
        $this->load($params);
48
49
        if (!$this->validate()) {
50
            return $dataProvider;
51
        }
52
53
        $query->andFilterWhere([
54
            'id' => $this->id,
55
        ]);
56
57
        $query->andFilterWhere(['like', 'param_key', $this->param_key])
58
            ->andFilterWhere(['like', 'param_value', $this->param_value])
59
            ->andFilterWhere(['like', 'description', $this->description])
60
            ->andFilterWhere(['like', 'validator', $this->validator]);
61
62
        return $dataProvider;
63
    }
64
}
65