Code Duplication    Length = 116-116 lines in 2 locations

system/modules/Ecommerce/models/Item/Offer/Param.php 1 location

@@ 14-129 (lines=116) @@
11
12
namespace Ecommerce\Item\Offer;
13
14
class Param extends \Model
15
{
16
    public static $objectName = 'Параметр товара';
17
    public static $labels = [
18
        'item_offer_option_id' => 'Параметр предложения',
19
        'item_offer_id' => 'Предложение',
20
        'value' => 'Значение',
21
    ];
22
    public static $cols = [
23
        //Основные параметры
24
        'item_offer_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'offer'],
25
        'item_offer_option_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'option', 'onChange' => 'reloadForm'],
26
        'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'],
27
        //Системные
28
        'date_create' => ['type' => 'dateTime']
29
    ];
30
31
    public static function indexes()
32
    {
33
        return [
34
            'ecommerce_itemOfferOptionRelation' => [
35
                'type' => 'INDEX',
36
                'cols' => [
37
                    'item_offer_param_item_offer_id',
38
                    'item_offer_param_item_offer_option_id'
39
                ]
40
            ],
41
            'ecommerce_paramItemOfferIndex' => [
42
                'type' => 'INDEX',
43
                'cols' => [
44
                    'item_offer_param_item_offer_id',
45
                ]
46
            ],
47
            'ecommerce_paramOfferOptionIndex' => [
48
                'type' => 'INDEX',
49
                'cols' => [
50
                    'item_offer_param_item_offer_option_id'
51
                ]
52
            ],
53
        ];
54
    }
55
56
    public function realType()
57
    {
58
        if ($this->option && $this->option->type)  {
59
            $type = $this->option->type;
60
61
            if ($type == 'select') {
62
                return [
63
                    'type' => 'select',
64
                    'source' => 'relation',
65
                    'relation' => 'option:items',
66
                ];
67
            }
68
            return $type;
69
        }
70
        return 'text';
71
    }
72
73
    public static $dataManagers = [
74
75
        'manager' => [
76
            'name' => 'Параметры предложения',
77
            'cols' => [
78
                'item_offer_option_id',
79
                'item_offer_id',
80
                'value',
81
            ],
82
        ],
83
    ];
84
    public static $forms = [
85
        'manager' => [
86
            'map' => [
87
                ['item_offer_id', 'item_offer_option_id'],
88
                ['value']
89
            ]
90
    ]];
91
92
    function name()
93
    {
94
        return $this->value;
95
    }
96
97
    public function value($default = '')
98
    {
99
        if ($this->option->type != 'select') {
100
            return $this->value;
101
        } elseif ($this->optionItem) {
102
            return $this->optionItem->value;
103
        }
104
        return $default;
105
    }
106
107
    public static function relations()
108
    {
109
        return [
110
            'file' => [
111
                'model' => 'Files\File',
112
                'col' => 'value'
113
            ],
114
            'option' => [
115
                'model' => 'Ecommerce\Item\Offer\Option',
116
                'col' => 'item_offer_option_id'
117
            ],
118
            'offer' => [
119
                'model' => 'Ecommerce\Item\Offer',
120
                'col' => 'item_offer_id'
121
            ],
122
            'optionItem' => [
123
                'model' => 'Ecommerce\Item\Offer\Option\Item',
124
                'col' => 'value'
125
            ]
126
        ];
127
    }
128
129
}
130

system/modules/Ecommerce/models/Item/Param.php 1 location

@@ 14-129 (lines=116) @@
11
12
namespace Ecommerce\Item;
13
14
class Param extends \Model
15
{
16
    public static $objectName = 'Параметр товара';
17
    public static $labels = [
18
        'item_option_id' => 'Параметр',
19
        'item_id' => 'Товар',
20
        'value' => 'Значение',
21
    ];
22
    public static $cols = [
23
        //Основные параметры
24
        'item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'item'],
25
        'item_option_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'option', 'onChange' => 'reloadForm'],
26
        'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType'],
27
        //Системные
28
        'date_create' => ['type' => 'dateTime']
29
    ];
30
31
    public static function indexes()
32
    {
33
        return [
34
            'ecommerce_itemOptionRelation' => [
35
                'type' => 'INDEX',
36
                'cols' => [
37
                    'item_param_item_id',
38
                    'item_param_item_option_id'
39
                ]
40
            ],
41
            'ecommerce_paramItemIndex' => [
42
                'type' => 'INDEX',
43
                'cols' => [
44
                    'item_param_item_id',
45
                ]
46
            ],
47
            'ecommerce_paramOptionIndex' => [
48
                'type' => 'INDEX',
49
                'cols' => [
50
                    'item_param_item_option_id'
51
                ]
52
            ],
53
        ];
54
    }
55
56
    public function realType()
57
    {
58
        if ($this->option) {
59
            $type = $this->option->type;
60
61
            if ($type == 'select') {
62
                return [
63
                    'type' => 'select',
64
                    'source' => 'relation',
65
                    'relation' => 'option:items',
66
                ];
67
            }
68
            return $type;
69
        }
70
        return 'text';
71
    }
72
73
    public static $dataManagers = [
74
75
        'manager' => [
76
            'name' => 'Параметры товара',
77
            'cols' => [
78
                'item_option_id',
79
                'item_id',
80
                'value',
81
            ],
82
        ],
83
    ];
84
    public static $forms = [
85
        'manager' => [
86
            'map' => [
87
                ['item_id', 'item_option_id'],
88
                ['value']
89
            ]
90
    ]];
91
92
    function name()
93
    {
94
        return $this->value;
95
    }
96
97
    public function value($default = '')
98
    {
99
        if ($this->option->type != 'select') {
100
            return $this->value;
101
        } elseif ($this->optionItem) {
102
            return $this->optionItem->value;
103
        }
104
        return $default;
105
    }
106
107
    public static function relations()
108
    {
109
        return [
110
            'file' => [
111
                'model' => 'Files\File',
112
                'col' => 'value'
113
            ],
114
            'option' => [
115
                'model' => 'Ecommerce\Item\Option',
116
                'col' => 'item_option_id'
117
            ],
118
            'item' => [
119
                'model' => 'Ecommerce\Item',
120
                'col' => 'item_id'
121
            ],
122
            'optionItem' => [
123
                'model' => 'Ecommerce\Item\Option\Item',
124
                'col' => 'value'
125
            ]
126
        ];
127
    }
128
129
}
130