DashboardSearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scenarios() 0 5 1
A rules() 0 7 1
B search() 0 26 2
1
<?php
2
3
namespace cornernote\dashboard\models\search;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use cornernote\dashboard\models\Dashboard;
9
10
/**
11
 * DashboardSearch represents the model behind the search form about `cornernote\dashboard\models\Dashboard`.
12
 */
13
class DashboardSearch extends Dashboard
14
{
15
16
    /**
17
     * @inheritdoc
18
     */
19
    public function scenarios()
20
    {
21
        // bypass parent scenarios
22
        return Model::scenarios();
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function rules()
29
    {
30
        return [
31
            [['id', 'enabled', 'sort'], 'integer'],
32
            [['name', 'layout_class'], 'safe'],
33
        ];
34
    }
35
36
    /**
37
     * Creates data provider instance with search query applied
38
     *
39
     * @param array $params
40
     *
41
     * @return ActiveDataProvider
42
     */
43
    public function search($params)
44
    {
45
        $query = Dashboard::find();
46
47
        $dataProvider = new ActiveDataProvider([
48
            'query' => $query,
49
            'sort' => ['defaultOrder' => ['sort' => SORT_ASC]],
50
        ]);
51
52
        $this->load($params);
53
54
        if (!$this->validate()) {
55
            return $dataProvider;
56
        }
57
58
        $query->andFilterWhere([
59
            'id' => $this->id,
60
            'enabled' => $this->enabled,
61
            'sort' => $this->sort,
62
        ]);
63
64
        $query->andFilterWhere(['like', 'name', $this->name])
65
            ->andFilterWhere(['like', 'layout_class', $this->layout_class]);
66
67
        return $dataProvider;
68
    }
69
70
}