ChargeQuery::attributesMap()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 30
c 2
b 0
f 0
dl 0
loc 41
ccs 0
cts 41
cp 0
rs 9.44
cc 1
nc 1
nop 0
crap 2
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\charge;
12
13
use hiqdev\billing\hiapi\models\Charge;
14
15
class ChargeQuery extends \hiqdev\yii\DataMapper\query\Query
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $modelClass = Charge::class;
21
22
    protected function attributesMap()
23
    {
24
        return [
25
            'id' => 'zh.id',
26
            'bill' => [
27
                'id' => 'zh.bill_id',
28
            ],
29
            'type' => [
30
                'id' => 'zh.type_id',
31
                'name' => 'ht.g2name',
32
            ],
33
            'target' => [
34
                'id' => 'zh.object_id',
35
                'type' => 'tt.name',
36
            ],
37
            'action' => [
38
                'id' => 'zh.action_id',
39
                'customer' => [
40
                    'id' => 'zc.obj_id',
41
                    'login' => 'zc.login',
42
                    'seller' => [
43
                        'id' => 'cr.obj_id',
44
                        'login' => 'cr.login',
45
                    ],
46
                ],
47
                'quantity' => [
48
                    'unit' => 'hu.parent',
49
                    'quantity' => 'ha.amount',
50
                ],
51
                'time' => 'ha.time',
52
            ],
53
            'sum' => [
54
                'currency' => 'py.name',
55
                'amount' => 'zh.sum',
56
            ],
57
            'usage' => [
58
                'unit' => 'hu.name',
59
                'quantity' => 'zh.quantity',
60
            ],
61
            'parent' => [
62
                'id' => 'zh.parent_id',
63
            ]
64
        ];
65
    }
66
67
    public function initFrom()
68
    {
69
        return $this->from('zcharge zh')
70
            ->leftJoin('purse       hp', 'hp.obj_id = zh.purse_id')
71
            ->leftJoin('zclient     zc', 'zc.obj_id = hp.client_id')
72
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id')
73
            ->leftJoin('zref        py', 'py.obj_id = hp.currency_id')
74
            ->leftJoin('unit        hu', 'hu.obj_id = zh.unit_id')
75
            ->leftJoin('action      ha', 'ha.id = zh.action_id')
76
            ->leftJoin('obj         tj', 'tj.obj_id = zh.object_id')
77
            ->leftJoin('zref        tt', 'tt.obj_id = tj.class_id')
78
            ->leftJoin('gref        ht', 'ht.obj_id = zh.type_id');
79
    }
80
}
81