PriceQuery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 26
dl 0
loc 43
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A attributesMap() 0 24 1
A initFrom() 0 9 1
1
<?php
2
/**
3
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\price;
12
13
use hiqdev\billing\hiapi\models\Price;
14
15
/**
16
 * Class PriceQuery.
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class PriceQuery extends \hiqdev\yii\DataMapper\query\Query
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $modelClass = Price::class;
25
26
    protected function attributesMap()
27
    {
28
        return [
29
            'id' => 'zp.id',
30
            'plan' => [
31
                'id' => 'zp.tariff_id',
32
            ],
33
            'target' => [
34
                'id' => 'zp.object_id',
35
                'type' => 'oc.name',
36
            ],
37
            'type' => [
38
                'id' => 'zp.type_id',
39
                'name' => 'rt.name',
40
            ],
41
            'price' => [
42
                'currency' => 'cu.name',
43
                'amount' => 'zp.price',
44
            ],
45
            'prepaid' => [
46
                'unit' => 'tu.name',
47
                'quantity' => 'zp.quantity',
48
            ],
49
            'data' => 'zp.data',
50
        ];
51
    }
52
53
    public function initFrom()
54
    {
55
        return $this
56
            ->from('uprice              zp')
57
            ->leftJoin('bill_type       rt', 'rt.obj_id = zp.type_id')
58
            ->leftJoin('zref            tu', 'tu.obj_id = zp.unit_id')
59
            ->leftJoin('zref            cu', 'cu.obj_id = zp.currency_id')
60
            ->leftJoin('obj             zo', 'zo.obj_id = zp.object_id')
61
            ->leftJoin('zref            oc', 'oc.obj_id = zo.class_id');
62
    }
63
}
64