MailerAccountSearch::search()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace backend\models\search;
3
4
use yii\base\Model;
5
use yii\data\ActiveDataProvider;
6
use backend\models\MailerAccount;
7
8
/**
9
 * MailerAccountSearch represents the model behind the search form of `backend\models\MailerAccount`.
10
 */
11
class MailerAccountSearch extends MailerAccount
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function rules()
17
    {
18
        return [
19
            [['domain_id'], 'integer'],
20
            [['email'], 'string'],
21
        ];
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function scenarios()
28
    {
29
        // bypass scenarios() implementation in the parent class
30
        return Model::scenarios();
31
    }
32
33
    /**
34
     * Creates data provider instance with search query applied
35
     *
36
     * @param array $params
37
     *
38
     * @return ActiveDataProvider
39
     */
40
    public function search($params)
41
    {
42
        $query = MailerAccount::find();
43
44
        // add conditions that should always apply here
45
46
        $dataProvider = new ActiveDataProvider([
47
            'query' => $query,
48
        ]);
49
50
        $this->load($params);
51
52
        if (!$this->validate()) {
53
            // uncomment the following line if you do not want to return any records when validation fails
54
            // $query->where('0=1');
55
            return $dataProvider;
56
        }
57
58
        // grid filtering conditions
59
        $query->andFilterWhere([
60
            'id' => $this->id,
61
            'domain_id' => $this->domain_id,
62
        ]);
63
64
        $query->andFilterWhere(['like', 'email', $this->email])
65
            ->andFilterWhere(['like', 'password', $this->password]);
66
67
        return $dataProvider;
68
    }
69
}
70