Test Failed
Push — master ( afbf72...42b272 )
by Alexey
04:43
created

Info::realType()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nc 4
nop 0
dl 20
loc 20
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Cart info
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ecommerce\Cart;
13
14 View Code Duplication
class Info extends \Model {
15
16
    public static $objectName = 'Информация';
17
    public static $labels = [
18
        'name' => 'Название',
19
        'value' => 'Значение',
20
        'useradds_field_id' => 'Поле',
21
        'cart_id' => 'Корзина'
22
    ];
23
    public static $cols = [
24
        'name' => ['type' => 'text'],
25
        'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'],
26
        'cart_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'cart'],
27
        'useradds_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'],
28
        //Системные параметры
29
        'date_create' => ['type' => 'dateTime'],
30
    ];
31
    public static $dataManagers = [
32
        'manager' => [
33
            'cols' => [
34
                'name',
35
                'value',
36
            ],
37
        ],
38
    ];
39
    public static $forms = [
40
        'manager' => [
41
            'map' => [
42
                ['name', 'value'],
43
                ['useradds_field_id', 'cart_id'],
44
            ]
45
        ]
46
    ];
47
48
    public static function relations() {
49
        return [
50
            'cart' => [
51
                'model' => 'Ecommerce\Cart',
52
                'col' => 'cart_id'
53
            ],
54
            'field' => [
55
                'model' => 'Ecommerce\UserAdds\Field',
56
                'col' => 'useradds_field_id'
57
            ]
58
        ];
59
    }
60
61
    public function realType() {
62
        if ($this->field && $this->field->type) {
63
            $type = $this->field->type;
64
65
            if ($type == 'select') {
66
                return [
67
                    'type' => 'select',
68
                    'source' => 'relation',
69
                    'relation' => 'field:fieldItems',
70
                ];
71
            } elseif ($type === 'autocomplete') {
72
                return [
73
                    'type' => 'autocomplete',
74
                    'options' => json_decode($this->field->options, true)
75
                ];
76
            }
77
            return $type;
78
        }
79
        return 'text';
80
    }
81
}
82