Completed
Push — master ( 5e7707...6e3d76 )
by Igor
03:56
created

AuthItemSearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 45
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 6 1
B search() 0 26 3
1
<?php
2
3
namespace app\modules\admin\models\search;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use app\models\AuthItem;
9
10
/**
11
 * AuthItemSearch represents the model behind the search form about `app\models\AuthItem`.
12
 */
13
class AuthItemSearch extends AuthItem
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function rules()
19
    {
20
        return [
21
            ['name', 'string'],
22
        ];
23
    }
24
25
    /**
26
     * Search by request criteria.
27
     *
28
     * @param array|null Filter params.
29
     * @return ActiveDataProvider Data provider.
30
     */
31
    public function search($params)
32
    {
33
        $query = AuthItem::find();
34
35
        $dataProvider = new ActiveDataProvider([
36
            'query' => $query,
37
            'sort' => [
38
                'defaultOrder' => [
39
                    'name' => SORT_ASC,
40
                ]
41
            ],
42
            'pagination' => [
43
                'pageSize' => 50,
44
            ],
45
        ]);
46
47
        $query->andFilterWhere(['type' => \yii\rbac\Item::TYPE_ROLE]);
48
49
        if (!($this->load($params) && $this->validate())) {
50
            return $dataProvider;
51
        }
52
53
        $query->andFilterWhere(['like', 'name', $this->name]);
54
55
        return $dataProvider;
56
    }
57
}
58