Sale::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 23
cp 0
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\models;
12
13
use Yii;
14
15
/**
16
 * Class Sale.
17
 *
18
 * @property string|int $id
19
 * @property string $object
20
 * @property string|int $object_id
21
 * @property string|int $tariff_id
22
 * @property string $tariff_type
23
 * @property string|int $buyer_id
24
 *
25
 * @author Dmytro Naumenko <[email protected]>
26
 */
27
class Sale extends \hipanel\base\Model
28
{
29
    use \hipanel\base\ModelTrait;
30
31
    const SALE_TYPE_IP = 'ip';
32
    const SALE_TYPE_DEVICE = 'device';
33
    const SALE_TYPE_SERVER = 'server';
34
    const SALE_TYPE_PCDN = 'pcdn';
35
    const SALE_TYPE_VCDN = 'vcdn';
36
    const SALE_TYPE_SWITCH = 'switch';
37
    const SALE_TYPE_ACCOUNT = 'account';
38
    const SALE_TYPE_CLIENT = 'client';
39
    const SALE_TYPE_PART = 'part';
40
    const SALE_TYPE_HARDWARE = 'model_group';
41
42
    public function rules()
43
    {
44
        return array_merge(parent::rules(), [
45
            [['id', 'buyer_id', 'seller_id', 'object_id', 'tariff_id'], 'integer'],
46
            [[
47
                'object',
48
                'object_like',
49
                'object_type',
50
                'seller',
51
                'login',
52
                'buyer',
53
                'tariff',
54
                'time',
55
                'expires',
56
                'renewed_num',
57
                'sub_factor',
58
                'tariff_type',
59
                'is_grouping',
60
                'from_old',
61
            ], 'string'],
62
            [['id'], 'required', 'on' => 'delete'],
63
            [['id', 'tariff_id', 'time'], 'required', 'on' => 'update'],
64
        ]);
65
    }
66
67
    public function attributeLabels()
68
    {
69
        return array_merge(parent::attributeLabels(), [
70
            'time' => Yii::t('hipanel:finance:sale', 'Time'),
71
            'object' => Yii::t('hipanel:finance:sale', 'Object'),
72
            'object_like' => Yii::t('hipanel:finance:sale', 'Object'),
73
            'object_type' => Yii::t('hipanel:finance:sale', 'Object type'),
74
            'buyer' => Yii::t('hipanel:finance:sale', 'Buyer'),
75
            'buyer_id' => Yii::t('hipanel:finance:sale', 'Buyer'),
76
            'seller' => Yii::t('hipanel:finance:sale', 'Seller'),
77
            'seller_id' => Yii::t('hipanel:finance:sale', 'Seller'),
78
            'tariff_id' => Yii::t('hipanel:finance', 'Tariff'),
79
            'tariff_type' => Yii::t('hipanel', 'Type'),
80
        ]);
81
    }
82
83
    public function getTypes()
84
    {
85
        return array_filter([
86
            self::SALE_TYPE_DEVICE => Yii::t('hipanel:finance', 'Servers'),
87
            self::SALE_TYPE_IP => 'IP',
88
            self::SALE_TYPE_ACCOUNT => Yii::t('hipanel', 'Accounts'),
89
            self::SALE_TYPE_CLIENT => Yii::t('hipanel', 'Clients'),
90
            self::SALE_TYPE_PART => Yii::getAlias('@part', false) ? Yii::t('hipanel:stock', 'Parts') : null,
91
        ]);
92
    }
93
}
94