Completed
Push — master ( 9b9020...8f5910 )
by Razon
02:07
created

SettingController::getQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace App\Http\Api\Backend\Controller;
3
4
use App\Http\Api\Backend\Model\Setting;
5
use yii\base\DynamicModel;
6
use Yii;
7
8
class SettingController extends ActiveController
9
{
10
    public $modelClass = Setting::class;
11
12
    public function actions()
13
    {
14
        $actions = parent::actions();
15
        return [
16
            'index' => $actions['index'],
17
            'view' => $actions['view'],
18
            'update' => $actions['update'],
19
            'options' => $actions['options'],
20
        ];
21
    }
22
23
    public function searchModel()
24
    {
25
        return (new DynamicModel(['id' => '', 'description' => '']))
26
            ->addRule(['id', 'description'], 'string');
27
    }
28
29
    protected function getQuery($action)
30
    {
31
        return parent::getQuery($action)
32
            ->alias('s')
33
            ->orderBy(['id' => SORT_ASC]);
34
    }
35
36
    protected function applyFilter($query, $model, $filter)
37
    {
38
        foreach (['id', 'description'] as $name) {
39
            if (!empty($model->$name)) {
40
                $query->andWhere(['LIKE', 's.' . $name, $model->$name]);
41
            }
42
        }
43
    }
44
}