SaleQuery   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 2
eloc 25
c 2
b 1
f 1
dl 0
loc 42
ccs 0
cts 34
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A attributesMap() 0 24 1
A initFrom() 0 8 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\sale;
12
13
use hiqdev\billing\hiapi\models\Sale;
14
15
class SaleQuery extends \hiqdev\yii\DataMapper\query\Query
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $modelClass = Sale::class;
21
22
    protected function attributesMap()
23
    {
24
        return [
25
            'id' => 'zs.obj_id',
26
            'target' => [
27
                'id' => 'zs.object_id',
28
                'type' => 'oc.name',
29
            ],
30
            'customer' => [
31
                'id' => 'zc.obj_id',
32
                'login' => 'zc.login',
33
                'seller' => [
34
                    'id' => 'cr.obj_id',
35
                    'login' => 'cr.login',
36
                ],
37
            ],
38
            'seller' => [
39
                'id' => 'zs.seller_id',
40
            ],
41
            'plan' => [
42
                'id' => 'zs.tariff_id',
43
                'name' => 'zt.tariff',
44
            ],
45
            'time' => 'zs.time',
46
        ];
47
    }
48
49
    public function initFrom()
50
    {
51
        return $this->from('zsale   zs')
52
            ->leftJoin('obj         so', 'so.obj_id = zs.object_id')
53
            ->leftJoin('zref        oc', 'oc.obj_id = so.class_id')
54
            ->leftJoin('ztariff     zt', 'zt.obj_id = zs.tariff_id')
55
            ->leftJoin('zclient     zc', 'zc.obj_id = zs.buyer_id')
56
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id');
57
    }
58
}
59