Completed
Push — master ( dbaf03...a19a70 )
by Andrii
14:13
created

PriceQuery::initFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace hiqdev\billing\hiapi\plan;
4
5
use hiqdev\billing\hiapi\models\Price;
6
7
class PriceQuery extends \hiapi\query\Query
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $modelClass = Price::class;
13
14
    protected function attributesMap()
15
    {
16
        return [
17
            'id' => 'tr.id',
18
            'plan' => [
19
                'id' => 'tr.tariff_id',
20
            ],
21
            'target' => [
22
                'id' => 'tr.object_id',
23
                'type' => 'oc.name',
24
            ],
25
            'type' => [
26
                'name' => 'rt.name',
27
            ],
28
            'price' => [
29
                'currency' => 'cu.name',
30
                'amount' => 'tr.price',
31
            ],
32
            'quantity' => [
33
                'unit' => 'tu.name',
34
                'quantity' => 'tr.quantity',
35
            ],
36
            'data' => 'tr.data',
37
        ];
38
    }
39
40
    public function initFrom()
41
    {
42
        return $this
43
            ->from('tariff_resourcez    tr')
44
            ->leftJoin('zref            rt', 'rt.obj_id = tr.type_id')
45
            ->leftJoin('zref            tu', 'tu.obj_id = tr.unit_id')
46
            ->leftJoin('zref            cu', 'cu.obj_id = tr.currency_id')
47
            ->leftJoin('obj             zo', 'zo.obj_id = zb.object_id')
48
            ->leftJoin('zref            oc', 'oc.obj_id = zo.class_id')
49
        ;
50
    }
51
}
52