Module::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace common\models\search;
4
5
use common\models\Module as ModuleModel;
6
use Yii;
7
use yii\base\Model;
8
use yii\data\ActiveDataProvider;
9
10
/**
11
 * Module represents the model behind the search form about `common\models\Module`.
12
 *
13
 * @author Agiel K. Saputra <[email protected]>
14
 * @since 0.2.0
15
 */
16
class Module extends ModuleModel
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function rules()
22
    {
23
        return [
24
            [['id', 'status', 'backend_bootstrap', 'frontend_bootstrap'], 'integer'],
25
            [['name', 'title', 'description', 'config', 'directory', 'date', 'modified'], 'safe'],
26
        ];
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function scenarios()
33
    {
34
        // bypass scenarios() implementation in the parent class
35
        return Model::scenarios();
36
    }
37
38
    /**
39
     * Creates data provider instance with search query applied
40
     *
41
     * @param array $params
42
     * @return ActiveDataProvider
43
     */
44
    public function search($params)
45
    {
46
        $query = ModuleModel::find();
47
48
        $dataProvider = new ActiveDataProvider([
49
            'query' => $query,
50
        ]);
51
52
        $this->load($params);
53
        if (!$this->validate()) {
54
            return $dataProvider;
55
        }
56
57
        $query->andFilterWhere([
58
            'id' => $this->id,
59
            'status' => $this->status,
60
            'backend_bootstrap' => $this->backend_bootstrap,
61
            'frontend_bootstrap' => $this->frontend_bootstrap,
62
            'date' => $this->date,
63
            'modified' => $this->modified,
64
        ]);
65
66
        $query->andFilterWhere(['like', 'name', $this->name])
67
            ->andFilterWhere(['like', 'title', $this->title])
68
            ->andFilterWhere(['like', 'description', $this->description])
69
            ->andFilterWhere(['like', 'config', $this->config])
70
            ->andFilterWhere(['like', 'directory', $this->directory]);
71
72
        return $dataProvider;
73
    }
74
}
75