SystemLogSearch::scenarios()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace monsterhunter\yii2\log\models\search;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use monsterhunter\yii2\log\models\SystemLog;
9
10
/**
11
 * SystemLogSearch represents the models behind the search form about `backend\models\SystemLog`.
12
 */
13
class SystemLogSearch extends SystemLog
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 2
    public function rules()
19
    {
20
        return [
21 2
            [['id', 'log_time', 'message'], 'integer'],
22
            [['category', 'prefix', 'level'], 'safe'],
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 2
    public function scenarios()
30
    {
31
        // bypass scenarios() implementation in the parent class
32 2
        return Model::scenarios();
33
    }
34
35
    /**
36
     * Creates data provider instance with search query applied
37
     * @return ActiveDataProvider
38
     */
39 2
    public function search($params)
40
    {
41 2
        $query = SystemLog::find();
42
43 2
        $dataProvider = new ActiveDataProvider([
44 2
            'query' => $query,
45
        ]);
46
47 2
        if (!($this->load($params) && $this->validate())) {
48
            return $dataProvider;
49
        }
50
51 2
        $query->andFilterWhere([
52 2
            'id' => $this->id,
53 2
            'level' => $this->level,
54 2
            'log_time' => $this->log_time,
55 2
            'message' => $this->message,
56
        ]);
57
58 2
        $query->andFilterWhere(['like', 'category', $this->category])
59 2
            ->andFilterWhere(['like', 'prefix', $this->prefix]);
60
61 2
        return $dataProvider;
62
    }
63
}
64