AlbumSearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 73
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 18 1
A search() 0 30 2
A scenarios() 0 4 1
1
<?php
2
3
namespace Itstructure\MFUploader\models\album;
4
5
use yii\base\Model;
6
use yii\data\ActiveDataProvider;
7
8
/**
9
 * AlbumSearch represents the model behind the search form of `Itstructure\MFUploader\models\Album`.
10
 */
11
class AlbumSearch extends Album
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [
20
                [
21
                    'id',
22
                    'created_at',
23
                    'updated_at'
24
                ],
25
                'integer'
26
            ],
27
            [
28
                [
29
                    'title',
30
                    'description',
31
                    'type'
32
                ],
33
                'safe'
34
            ],
35
        ];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function scenarios()
42
    {
43
        // bypass scenarios() implementation in the parent class
44
        return Model::scenarios();
45
    }
46
47
    /**
48
     * Creates data provider instance with search query applied
49
     *
50
     * @param array $params
51
     *
52
     * @return ActiveDataProvider
53
     */
54
    public function search($params)
55
    {
56
        $query = Album::find();
57
58
        // add conditions that should always apply here
59
60
        $dataProvider = new ActiveDataProvider([
61
            'query' => $query,
62
        ]);
63
64
        $this->load($params);
65
66
        if (!$this->validate()) {
67
            // uncomment the following line if you do not want to return any records when validation fails
68
            // $query->where('0=1');
69
            return $dataProvider;
70
        }
71
72
        // grid filtering conditions
73
        $query->andFilterWhere([
74
            'id' => $this->id,
75
            'created_at' => $this->created_at,
76
            'updated_at' => $this->updated_at,
77
        ]);
78
79
        $query->andFilterWhere(['like', 'title', $this->title])
80
            ->andFilterWhere(['like', 'description', $this->description])
81
            ->andFilterWhere(['like', 'type', $this->type]);
82
83
        return $dataProvider;
84
    }
85
}
86