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

TargetQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 30
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A attributesMap() 0 14 1
A initFrom() 0 7 1
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