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

AuthItemSearch::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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