Completed
Push — master ( 22330a...e8d007 )
by Dmitry
01:58
created

TargetQuery::attributesMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\target;
4
5
use hiqdev\billing\hiapi\models\Target;
6
use yii\db\Expression;
7
8
class TargetQuery extends \hiqdev\yii\DataMapper\query\Query
9
{
10
    protected $modelClass = Target::class;
11
12
    /**
13
     * @return array
14
     */
15
    protected function attributesMap()
16
    {
17
        return [
18
            'id' => 'o.obj_id',
19
            'type' => new Expression("
20
                t.name || 
21
                CASE WHEN tt.name IS NOT NULL THEN
22
                    '.' || tt.name
23
                ELSE
24
                    ''
25
                END as type
26
            "),
27
        ];
28
    }
29
30
    public function initFrom()
31
    {
32
        return $this->from('obj   o')
33
                ->leftJoin('zref   t',  't.obj_id  = o.class_id')
34
                ->leftJoin('device d',  'd.obj_id  = o.obj_id')
35
                ->leftJoin('zref   tt', 'tt.obj_id = coalesce(d.type_id)');
36
    }
37
}
38