Completed
Push — master ( 05f0c6...d5b4df )
by Dmitry
03:21
created

CustomerQuery::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 1
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\query;
4
5
use hiapi\query\Field;
6
use hiqdev\billing\hiapi\models\Customer;
7
8
class CustomerQuery extends \hiapi\query\Query
9
{
10
    public function getFields()
11
    {
12
        return $this->fieldFactory->createByModelAttributes(new Customer(), [
13
            'id' => 'zc.obj_id',
14
            'login' => 'zc.login',
15
            'seller-id' => 'cr.obj_id',
16
            'seller-login' => 'zc.login',
17
        ]);
18
    }
19
20
    public function initSelect()
21
    {
22
        return $this->selectByFields($this->getFields())
23
            ->from('zclient         zc')
24
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id');
25
    }
26
27
    /**
28
     * @param Field[] $fields
29
     * @return $this
30
     */
31
    protected function selectByFields($fields)
32
    {
33
        foreach ($fields as $field) {
34
            if ($field->canBeSelected()) {
35
                $this->addSelect($field->getSql() . ' as ' . $field->getName());
36
            }
37
        }
38
39
        return $this;
40
    }
41
}
42