Completed
Push — master ( b812ef...80282b )
by monster
01:45
created

SettingSearch::scenarios()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @link http://phe.me
4
 * @copyright Copyright (c) 2014 Pheme
5
 * @license MIT http://opensource.org/licenses/MIT
6
 */
7
8
namespace pheme\settings\models;
9
10
use Yii;
11
use yii\base\Model;
12
use yii\data\ActiveDataProvider;
13
14
/**
15
 * SettingSearch represents the model behind the search form about `pheme\settings\models\Setting`.
16
 *
17
 * @author Aris Karageorgos <[email protected]>
18
 */
19
class SettingSearch extends Setting
20
{
21
    /**
22
     * @return array
23
     */
24 1
    public function rules()
25
    {
26
        return [
27 1
            [['id'], 'integer'],
28 1
            [['active'], 'boolean'],
29 1
            [['type', 'section', 'key', 'value', 'created', 'modified'], 'safe'],
30 1
        ];
31
    }
32
33
    /**
34
     * @return array
35
     */
36 1
    public function scenarios()
37
    {
38
        // bypass scenarios() implementation in the parent class
39 1
        return Model::scenarios();
40
    }
41
42
    /**
43
     * @param $params
44
     * @return ActiveDataProvider
45
     */
46 1
    public function search($params)
47
    {
48 1
        $query = Setting::find();
49
50 1
        $dataProvider = new ActiveDataProvider(
51
            [
52 1
                'query' => $query,
53
            ]
54 1
        );
55
56 1
        if (!($this->load($params) && $this->validate())) {
57
            return $dataProvider;
58
        }
59
60 1
        $query->andFilterWhere(
61
            [
62 1
                'id' => $this->id,
63 1
                'active' => $this->active,
64 1
                'section' => $this->section,
65
            ]
66 1
        );
67
68 1
        $query->andFilterWhere(['like', 'key', $this->key])
69 1
            ->andFilterWhere(['like', 'value', $this->value]);
70
71 1
        return $dataProvider;
72
    }
73
}
74