Completed
Push — master ( 5071d1...56b015 )
by Klochok
14:27
created

Hub   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 64
c 2
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B rules() 0 28 1
A attributeLabels() 0 21 1
A getBindings() 0 4 1
1
<?php
2
3
namespace hipanel\modules\server\models;
4
5
use hipanel\modules\server\validators\MacValidator;
6
use Yii;
7
8
class Hub extends \hipanel\base\Model
9
{
10
    use \hipanel\base\ModelTrait;
11
12
    const SCENARIO_CREATE = 'create';
13
    const SCENARIO_UPDATE = 'update';
14
    const SCENARIO_OPTIONS = 'options';
15
16
    public function rules()
17
    {
18
        return array_merge(parent::rules(), [
19
            [['id', 'access_id', 'type_id', 'state_id', 'buyer_id', 'units'], 'integer'],
20
            [[
21
                'name', 'dc', 'mac', 'remoteid', 'note', 'ip', 'type_label', 'buyer', 'note', 'inn', 'model',
22
                'community', 'login', 'traf_server_id', 'order_no', 'password', 'ports_num', 'traf_server_id',
23
                'vlan_server_id', 'community', 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no',
24
                'oob_key',
25
            ], 'string'],
26
            [['virtual'], 'boolean'],
27
28
            // Create and update
29
            [['type_id', 'name'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
30
            [['id'], 'integer', 'on' => self::SCENARIO_UPDATE],
31
            [['inn', 'mac', 'ip', 'model', 'order_no', 'note'], 'string', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
32
33
            // set Options
34
            [[
35
                'id', 'inn', 'model', 'login', 'password', 'ports_num', 'community',
36
                'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', 'base_port_no',
37
            ], 'safe', 'on' => 'options'],
38
            [['traf_server_id', 'vlan_server_id'], 'integer', 'on' => self::SCENARIO_OPTIONS],
39
40
            [['ip'], 'ip', 'on' => ['create', 'update', 'options']],
41
            [['mac'], MacValidator::class],
42
        ]);
43
    }
44
45
    public function attributeLabels()
46
    {
47
        return array_merge(parent::attributeLabels(), [
48
            'type_id' => Yii::t('hipanel', 'Type'),
49
            'inn' => Yii::t('hipanel:server:hub', 'INN'),
50
            'model' => Yii::t('hipanel:server:hub', 'Model'),
51
            'order_no' => Yii::t('hipanel:server:hub', 'Order No.'),
52
            'login' => Yii::t('hipanel:server:hub', 'Login'),
53
            'password' => Yii::t('hipanel:server:hub', 'Password'),
54
            'ports_num' => Yii::t('hipanel:server:hub', 'Number of ports'),
55
            'traf_server_id' => Yii::t('hipanel:server:hub', 'Server where traf is counted'),
56
            'vlan_server_id' => Yii::t('hipanel:server:hub', 'Server in same VLAN'),
57
            'community' => Yii::t('hipanel:server:hub', 'Community'),
58
            'snmp_version_id' => Yii::t('hipanel:server:hub', 'SNMP version'),
59
            'digit_capacity_id' => Yii::t('hipanel:server:hub', 'Digit capacity'),
60
            'nic_media' => Yii::t('hipanel:server:hub', 'NIC media'),
61
            'base_port_no' => Yii::t('hipanel:server:hub', 'Base port no'),
62
            'oob_key' => Yii::t('hipanel:server:hub', 'OOB license key'),
63
            'mac' => Yii::t('hipanel:server:hub', 'MAC address')
64
        ]);
65
    }
66
67
    public function getBindings()
68
    {
69
        return $this->hasMany(Binding::class, ['device_id' => 'id'])->indexBy('type');
70
    }
71
}
72