<commit_before><?php
/**
 * Server module for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-server
 * @package   hipanel-module-server
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\server\models;

use hipanel\base\Model;
use hipanel\base\ModelTrait;
use hipanel\modules\server\models\query\HubQuery;
use hipanel\modules\server\models\traits\AssignSwitchTrait;
use hipanel\modules\server\validators\MacValidator;
use hipanel\modules\stock\models\Part;
use hiqdev\hiart\ActiveQuery;
use Yii;

class Hub extends Model implements AssignSwitchInterface
{
    use ModelTrait, AssignSwitchTrait;

    const SCENARIO_CREATE = 'create';
    const SCENARIO_UPDATE = 'update';
    const SCENARIO_OPTIONS = 'options';
    public const STATE_OK = 'ok';
    public const STATE_DELETED = 'deleted';


    public function rules()
    {
        return array_merge(parent::rules(), [
            [['id', 'access_id', 'type_id', 'state_id', 'buyer_id', 'units', 'tariff_id', 'client_id'], 'integer'],
            [['tariff'], 'safe'],
            [[
                'name', 'dc', 'mac', 'remoteid', 'note', 'ip', 'type_label', 'buyer', 'note', 'inn', 'model',
                'community', 'traf_server_id', 'order_no', 'ports_num', 'traf_server_id',
                'login', 'password', 'user_login', 'user_password',
                'vlan_server_id', 'community', 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no',
                'oob_key', 'traf_server_id_label', 'vlan_server_id_label', 'type', 'state', 'state_label',
            ], 'string'],
            [['virtual'], 'boolean'],

            [['tariff_id', 'sale_time'], 'required', 'on' => ['sale']],

            // Create and update
            [['type_id', 'name'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
            [['name', 'mac', 'ip'], 'unique', 'filter' => function ($query) {
                $query->andWhere(['ne', 'id', $this->id]);
            }, 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
            [['id'], 'integer', 'on' => self::SCENARIO_UPDATE],
            [['inn', 'mac', 'ip', 'model', 'order_no', 'note'], 'string', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],

            // set Options
            [[
                'id', 'inn', 'model', 'login', 'password', 'ports_num', 'community',
                'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', 'base_port_no',
                'user_login', 'user_password',
            ], 'safe', 'on' => 'options'],
            [['traf_server_id', 'vlan_server_id'], 'integer', 'on' => self::SCENARIO_OPTIONS],

            [['ip'], 'ip', 'on' => ['create', 'update', 'options']],
            [['mac'], MacValidator::class],<commit_msg>HP-949: add stat info for admin<commit_after><?php
/**
 * Server module for HiPanel
 *
 * @link      https://github.com/hiqdev/hipanel-module-server
 * @package   hipanel-module-server
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
 */

namespace hipanel\modules\server\models;

use hipanel\base\Model;
use hipanel\base\ModelTrait;
use hipanel\modules\server\models\query\HubQuery;
use hipanel\modules\server\models\traits\AssignSwitchTrait;
use hipanel\modules\server\validators\MacValidator;
use hipanel\modules\stock\models\Part;
use hiqdev\hiart\ActiveQuery;
use Yii;

class Hub extends Model implements AssignSwitchInterface
{
    use ModelTrait, AssignSwitchTrait;

    const SCENARIO_CREATE = 'create';
    const SCENARIO_UPDATE = 'update';
    const SCENARIO_OPTIONS = 'options';
    public const STATE_OK = 'ok';
    public const STATE_DELETED = 'deleted';


    public function rules()
    {
        return array_merge(parent::rules(), [
            [['id', 'access_id', 'type_id', 'state_id', 'buyer_id', 'units', 'tariff_id', 'client_id'], 'integer'],
            [['tariff'], 'safe'],
            [[
                'name', 'dc', 'mac', 'remoteid', 'note', 'ip', 'type_label', 'buyer', 'note', 'inn', 'model',
                'community', 'traf_server_id', 'order_no', 'ports_num', 'traf_server_id',
                'login', 'password', 'user_login', 'user_password',
                'vlan_server_id', 'community', 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no',
                'oob_key', 'traf_server_id_label', 'vlan_server_id_label', 'type', 'state', 'state_label',
                'stat_device', 'stat_domain',
            ], 'string'],
            [['virtual'], 'boolean'],

            [['tariff_id', 'sale_time'], 'required', 'on' => ['sale']],

            // Create and update
            [['type_id', 'name'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
            [['name', 'mac', 'ip'], 'unique', 'filter' => function ($query) {
                $query->andWhere(['ne', 'id', $this->id]);
            }, 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
            [['id'], 'integer', 'on' => self::SCENARIO_UPDATE],
            [['inn', 'mac', 'ip', 'model', 'order_no', 'note'], 'string', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],

            // set Options
            [[
                'id', 'inn', 'model', 'login', 'password', 'ports_num', 'community',
                'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', 'base_port_no',
                'user_login', 'user_password',
            ], 'safe', 'on' => 'options'],
            [['traf_server_id', 'vlan_server_id'], 'integer', 'on' => self::SCENARIO_OPTIONS],

            [['ip'], 'ip', 'on' => ['create', 'update', 'options']],
            [['mac'], MacValidator::class],
{'fraction_non_alphanumeric': 0.189198606271777, 'fraction_numerical': 0.003658536585365854, 'mean_word_length': 3.062986553432413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393637', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1887, 'n_words': 376}