| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Server module for HiPanel |
||
| 4 | * |
||
| 5 | * @link https://github.com/hiqdev/hipanel-module-server |
||
| 6 | * @package hipanel-module-server |
||
| 7 | * @license BSD-3-Clause |
||
| 8 | * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace hipanel\modules\server\models; |
||
| 12 | |||
| 13 | use hipanel\base\Model; |
||
| 14 | use hipanel\base\ModelTrait; |
||
| 15 | use hipanel\modules\server\models\query\HubQuery; |
||
| 16 | use hipanel\modules\server\models\traits\AssignSwitchTrait; |
||
| 17 | use hipanel\modules\server\validators\MacValidator; |
||
| 18 | use hiqdev\hiart\ActiveQuery; |
||
| 19 | use Yii; |
||
| 20 | |||
| 21 | class Hub extends Model implements AssignSwitchInterface |
||
| 22 | { |
||
| 23 | use ModelTrait, AssignSwitchTrait; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 24 | |||
| 25 | const SCENARIO_CREATE = 'create'; |
||
| 26 | const SCENARIO_UPDATE = 'update'; |
||
| 27 | const SCENARIO_OPTIONS = 'options'; |
||
| 28 | |||
| 29 | public function rules() |
||
| 30 | { |
||
| 31 | return array_merge(parent::rules(), [ |
||
| 32 | [['id', 'access_id', 'type_id', 'state_id', 'buyer_id', 'units', 'tariff_id', 'client_id'], 'integer'], |
||
| 33 | [['tariff'], 'safe'], |
||
| 34 | [[ |
||
| 35 | 'name', 'dc', 'mac', 'remoteid', 'note', 'ip', 'type_label', 'buyer', 'note', 'inn', 'model', |
||
| 36 | 'community', 'login', 'traf_server_id', 'order_no', 'password', 'ports_num', 'traf_server_id', |
||
| 37 | 'vlan_server_id', 'community', 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', |
||
| 38 | 'oob_key', 'traf_server_id_label', 'vlan_server_id_label', 'type', |
||
| 39 | ], 'string'], |
||
| 40 | [['virtual'], 'boolean'], |
||
| 41 | |||
| 42 | [['tariff_id', 'sale_time'], 'required', 'on' => ['sale']], |
||
| 43 | |||
| 44 | // Create and update |
||
| 45 | [['type_id', 'name'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
||
| 46 | [['name', 'mac', 'ip'], 'unique', 'filter' => function ($query) { |
||
| 47 | $query->andWhere(['ne', 'id', $this->id]); |
||
|
0 ignored issues
–
show
The property
id does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 48 | }, 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
||
| 49 | [['id'], 'integer', 'on' => self::SCENARIO_UPDATE], |
||
| 50 | [['inn', 'mac', 'ip', 'model', 'order_no', 'note'], 'string', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
||
| 51 | |||
| 52 | // set Options |
||
| 53 | [[ |
||
| 54 | 'id', 'inn', 'model', 'login', 'password', 'ports_num', 'community', |
||
| 55 | 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', 'base_port_no', |
||
| 56 | ], 'safe', 'on' => 'options'], |
||
| 57 | [['traf_server_id', 'vlan_server_id'], 'integer', 'on' => self::SCENARIO_OPTIONS], |
||
| 58 | |||
| 59 | [['ip'], 'ip', 'on' => ['create', 'update', 'options']], |
||
| 60 | [['mac'], MacValidator::class], |
||
| 61 | [['id'], 'required', 'on' => 'delete'], |
||
| 62 | ]); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function attributeLabels() |
||
| 66 | { |
||
| 67 | return array_merge(parent::attributeLabels(), [ |
||
| 68 | 'type_id' => Yii::t('hipanel', 'Type'), |
||
| 69 | 'buyer_id' => Yii::t('hipanel:server:hub', 'Buyer'), |
||
| 70 | 'buyer' => Yii::t('hipanel:server:hub', 'Buyer'), |
||
| 71 | 'inn' => Yii::t('hipanel:server:hub', 'INN'), |
||
| 72 | 'inn_ilike' => Yii::t('hipanel:server:hub', 'INN'), |
||
| 73 | 'model' => Yii::t('hipanel:server:hub', 'Model'), |
||
| 74 | 'order_no' => Yii::t('hipanel:server:hub', 'Order No.'), |
||
| 75 | 'login' => Yii::t('hipanel:server:hub', 'Login'), |
||
| 76 | 'password' => Yii::t('hipanel:server:hub', 'Password'), |
||
| 77 | 'ports_num' => Yii::t('hipanel:server:hub', 'Number of ports'), |
||
| 78 | 'traf_server_id' => Yii::t('hipanel:server:hub', 'Server where traf is counted'), |
||
| 79 | 'vlan_server_id' => Yii::t('hipanel:server:hub', 'Server in same VLAN'), |
||
| 80 | 'community' => Yii::t('hipanel:server:hub', 'Community'), |
||
| 81 | 'snmp_version_id' => Yii::t('hipanel:server:hub', 'SNMP version'), |
||
| 82 | 'digit_capacity_id' => Yii::t('hipanel:server:hub', 'Digit capacity'), |
||
| 83 | 'nic_media' => Yii::t('hipanel:server:hub', 'NIC media'), |
||
| 84 | 'base_port_no' => Yii::t('hipanel:server:hub', 'Base port no'), |
||
| 85 | 'oob_key' => Yii::t('hipanel:server:hub', 'OOB license key'), |
||
| 86 | 'mac' => Yii::t('hipanel:server:hub', 'MAC address'), |
||
| 87 | 'name' => Yii::t('hipanel:server:hub', 'Name'), |
||
| 88 | 'note' => Yii::t('hipanel:server:hub', 'Note'), |
||
| 89 | 'net' => Yii::t('hipanel:server', 'Switch'), |
||
| 90 | 'kvm' => Yii::t('hipanel:server', 'KVM'), |
||
| 91 | 'pdu' => Yii::t('hipanel:server', 'APC'), |
||
| 92 | 'rack_like' => Yii::t('hipanel:server', 'Rack'), |
||
| 93 | 'ipmi' => Yii::t('hipanel:server', 'IPMI'), |
||
| 94 | 'location' => Yii::t('hipanel:server:hub', 'Location'), |
||
| 95 | 'name_ilike' => Yii::t('hipanel:server:hub', 'Switch'), |
||
| 96 | 'sale_time' => Yii::t('hipanel:server', 'Sale time'), |
||
| 97 | ]); |
||
| 98 | } |
||
| 99 | |||
| 100 | public function getBindings() |
||
| 101 | { |
||
| 102 | return $this->hasMany(Binding::class, ['device_id' => 'id'])->indexBy('type'); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function getBinding($type) |
||
| 106 | { |
||
| 107 | if (!isset($this->bindings[$type])) { |
||
|
0 ignored issues
–
show
The property
bindings does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 108 | return null; |
||
| 109 | } |
||
| 110 | |||
| 111 | return $this->bindings[$type]; |
||
| 112 | } |
||
| 113 | |||
| 114 | public function getHardwareSettings(): ActiveQuery |
||
| 115 | { |
||
| 116 | return $this->hasOne(HardwareSettings::class, ['id' => 'id']); |
||
| 117 | } |
||
| 118 | |||
| 119 | public function getMonitoringSettings() |
||
| 120 | { |
||
| 121 | return $this->hasOne(MonitoringSettings::class, ['id' => 'id']); |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | * @return HubQuery |
||
| 127 | */ |
||
| 128 | public static function find($options = []) |
||
| 129 | { |
||
| 130 | return new HubQuery(get_called_class(), [ |
||
| 131 | 'options' => $options, |
||
| 132 | ]); |
||
| 133 | } |
||
| 134 | } |
||
| 135 |