Test Failed
Push — master ( 23cc6e...476483 )
by Alexey
05:28
created

Price::relations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Item offer price
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\Item\Offer;
13
14
use Users\User;
15
16
/**
17
 * Class Price
18
 *
19
 * @property int $id
20
 * @property int $item_offer_id
21
 * @property int $item_offer_price_type_id
22
 * @property string $name
23
 * @property number $price
24
 * @property int $currency_id
25
 * @property int $weight
26
 * @property string $date_create
27
 *
28
 * @property-read \Ecommerce\Item\Offer $offer
29
 * @method \Ecommerce\Item\Offer offer($options)
30
 * @property-read \Ecommerce\Item\Offer\Price\Type $type
31
 * @method \Ecommerce\Item\Offer\Price\Type type($options)
32
 * @property-read \Money\Currency $currency
33
 * @method \Money\Currency currency($options)
34
 */
35
class Price extends \Model {
36
37
    public static $objectName = 'Цена';
38
    public static $cols = [
39
        //Основные параметры
40
        'item_offer_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'offer'],
41
        'item_offer_price_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'],
42
        'name' => ['type' => 'text'],
43
        'price' => ['type' => 'decimal'],
44
        'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'],
45
        //Системные
46
        'weight' => ['type' => 'text'],
47
        'date_create' => ['type' => 'dateTime'],
48
    ];
49
    public static $labels = [
50
        'price' => 'Цена',
51
        'item_offer_price_type_id' => 'Тип цены',
52
        'item_offer_id' => 'Товар',
53
        'currency_id' => 'Валюта',
54
    ];
55
    public static $dataManagers = [
56
        'manager' => [
57
            'name' => 'Цены',
58
            'cols' => [
59
                'item_offer_price_type_id',
60
                'price',
61
                'currency_id',
62
            ]
63
        ],
64
    ];
65
    public static $forms = [
66
        'manager' => [
67
            'map' => [
68
                ['price', 'currency_id'],
69
                ['item_offer_price_type_id']
70
            ]
71
        ]
72
    ];
73
74
    /**
75
     * @param bool|\Users\User $user
76
     * @return bool
77
     */
78
    public function checkUserAccess($user = false) {
79
        if (!$user) {
80
            $user = User::$cur;
81
        }
82
        return (!$this->type->roles) ||
83
            ($this->type->roles && strpos($this->type->roles, "|" . $user->role_id . "|") !== false);
84
    }
85
86
    public static function relations() {
87
        return [
88
            'offer' => [
89
                'model' => 'Ecommerce\Item\Offer',
90
                'col' => 'item_offer_id'
91
            ],
92
            'type' => [
93
                'model' => 'Ecommerce\Item\Offer\Price\Type',
94
                'col' => 'item_offer_price_type_id'
95
            ],
96
            'currency' => [
97
                'model' => 'Money\Currency',
98
                'col' => 'currency_id'
99
            ],
100
        ];
101
    }
102
103
}
104