public function init()
 {
     $this->header = Html::tag('h4', $this->title, ['class' => 'modal-title']);
     $this->actionUrl = [$this->scenario, 'id' => $this->model->id];
     $this->toggleButton = array_merge(['tag' => 'a', 'label' => FontIcon::i($this->icon) . $this->title, 'class' => 'clickable'], is_array($this->toggleButton) ? $this->toggleButton : []);
     parent::init();
 }
 public static function defaultColumns()
 {
     return ['ip' => ['class' => MainColumn::class, 'filterAttribute' => 'ip_like'], 'tags' => ['format' => 'raw', 'attribute' => 'tag', 'header' => Yii::t('hipanel:hosting', 'Tags'), 'visible' => Yii::$app->user->can('admin'), 'filter' => function ($column, $model) {
         return Html::activeDropDownList($model, 'tag_in', array_merge(['' => Yii::t('hipanel', '---')], static::$ipTags), ['class' => 'form-control']);
     }, 'value' => function ($model) {
         $labels = [];
         foreach ($model->tags as $tag) {
             $labels[] = IpTag::widget(['tag' => $tag]);
         }
         return implode(' ', $labels);
     }], 'counters' => ['format' => 'html', 'header' => Yii::t('hipanel:hosting', 'Counters'), 'value' => function ($model) {
         $html = '';
         foreach ($model->objects_count as $count) {
             if ($count['type'] === 'hdomain') {
                 $url['ok'] = ['@hdomain', (new HdomainSearch())->formName() => ['ip_like' => $model->ip]];
                 $url['deleted'] = ['@hdomain', (new HdomainSearch())->formName() => ['ip_like' => $model->ip, 'state' => 'deleted']];
                 $type = function ($count) {
                     return Yii::t('hipanel:hosting', '{0, plural, one{domain} other{domains}}', (int) $count);
                 };
             } else {
                 throw new InvalidParamException('The object type is not supported', $model);
             }
             if ($count['ok']) {
                 $html .= Html::a((int) $count['ok'] . ' ' . FontIcon::i('fa-check') . ' ' . $type($count['ok']), $url['ok'], ['class' => 'btn btn-success btn-xs']);
             }
             $html .= ' ';
             if ($count['deleted'] > 0) {
                 $html .= Html::a((int) $count['deleted'] . ' ' . FontIcon::i('fa-trash') . ' ' . $type($count['deleted']), $url['deleted'], ['class' => 'btn btn-xs btn-warning']);
             }
         }
         return $html;
     }], 'links' => ['format' => 'html', 'value' => function ($model) {
         $items = [];
         foreach ($model->links as $link) {
             $item = Html::a($link->device, ['@server/view', 'id' => $link->device_id]);
             if ($link->service_id) {
                 $item .= ' ' . FontIcon::i('fa-long-arrow-right');
                 $item .= ' ' . Html::a($link->service ?: $link->soft, ['@service/view', 'id' => $link->service_id]);
             }
             $items[] = $item;
         }
         return ArraySpoiler::widget(['data' => $items, 'visibleCount' => 3]);
     }], 'services' => ['attribute' => 'links', 'format' => 'html', 'label' => Yii::t('hipanel:server', 'Services'), 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => $model->links, 'formatter' => function ($link) {
             if (Yii::$app->user->can('support') && Yii::getAlias('@service', false)) {
                 return Html::a($link->service, ['@service/view', 'id' => $link->service_id]);
             }
             return $link->service;
         }]);
     }], 'actions' => ['class' => MenuColumn::class, 'menuClass' => IpActionsMenu::class], 'ptr' => ['options' => ['style' => 'width: 40%'], 'format' => 'raw', 'value' => function ($model) {
         if ($model->canSetPtr()) {
             return XEditable::widget(['model' => $model, 'attribute' => 'ptr', 'pluginOptions' => ['url' => Url::to('@ip/set-ptr')]]);
         }
         return null;
     }]];
 }
 public static function defaultColumns()
 {
     return ['service' => ['class' => MainColumn::class, 'attribute' => 'name', 'filterAttribute' => 'service_like'], 'server' => ['class' => ServerColumn::class], 'object' => ['format' => 'raw', 'header' => Yii::t('hipanel:hosting', 'Object'), 'value' => function ($model) {
         $html = $model->name . ' ';
         if ($model->soft_type === Soft::TYPE_WEB) {
             $url['ok'] = ['@hdomain', (new HdomainSearch())->formName() => ['server' => $model->server, 'service' => $model->name]];
             $url['deleted'] = ['@hdomain', (new HdomainSearch())->formName() => ['server' => $model->server, 'service' => $model->name, 'state' => 'deleted']];
             $type = function ($count) {
                 return Yii::t('hipanel:hosting', '{0, plural, one{domain} other{domains}}', (int) $count);
             };
         } elseif ($model->soft_type === Soft::TYPE_DB) {
             $url['ok'] = ['@db', (new DbSearch())->formName() => ['server' => $model->server, 'service' => $model->name]];
             $url['deleted'] = ['@db', (new DbSearch())->formName() => ['server' => $model->server, 'service' => $model->name, 'state' => 'deleted']];
             $type = function ($count) {
                 return Yii::t('hipanel:hosting', '{0, plural, one{# DB} other{# DBs}}', (int) $count);
             };
         } else {
             return $html;
         }
         if ($count = $model->objects_count['ok']) {
             $html .= Html::a((int) $count . ' ' . FontIcon::i('fa-check') . ' ' . $type($count), $url['ok'], ['class' => 'btn btn-success btn-xs']);
         }
         $html .= ' ';
         if (($count = $model->objects_count['deleted']) > 0) {
             $html .= Html::a((int) $count . ' ' . FontIcon::i('fa-trash') . ' ' . $type($count), $url['deleted'], ['class' => 'btn btn-xs btn-warning']);
         }
         return $html;
     }], 'ip' => ['format' => 'raw', 'label' => Yii::t('hipanel:hosting', 'IP'), 'value' => function ($model) {
         return ArraySpoiler::widget(['data' => array_unique(array_merge((array) $model->ip, (array) $model->ips))]);
     }], 'bin' => ['format' => 'html', 'value' => function ($model) {
         return $model->bin ? Html::tag('code', $model->bin) : '';
     }], 'etc' => ['format' => 'html', 'value' => function ($model) {
         return $model->etc ? Html::tag('code', $model->etc) : '';
     }], 'soft' => ['value' => function ($model) {
         return $model->soft;
     }], 'state' => ['class' => RefColumn::class, 'i18nDictionary' => 'hipanel:hosting', 'format' => 'raw', 'value' => function ($model) {
         return State::widget(compact('model'));
     }, 'gtype' => 'state,service'], 'actions' => ['class' => MenuColumn::class, 'menuClass' => ServiceActionsMenu::class]];
 }
 /**
  * Configures options of widget.
  */
 public function initOptions()
 {
     $model = $this->model;
     if ($this->action === null) {
         $this->action = $model->state === $model::STATE_BLOCKED ? self::ACTION_DISABLE : self::ACTION_ENABLE;
     }
     if ($this->scenario === null) {
         $this->scenario = $this->action === static::ACTION_ENABLE ? static::SCENARIO_ENABLE : static::SCENARIO_DISABLE;
     }
     if ($this->validationUrl === null) {
         $this->validationUrl = Url::toRoute(['validate-form', 'scenario' => $this->scenario]);
     }
     if ($this->blockReasons === null) {
         $this->blockReasons = Yii::$app->controller->getBlockReasons();
     }
     if (is_array($this->button)) {
         $this->button = ArrayHelper::merge([static::ACTION_ENABLE => ['label' => FontIcon::i('fa-lock fa-2x fa-fw') . Yii::t('hipanel', 'Enable block'), 'position' => ModalButton::BUTTON_OUTSIDE], static::ACTION_DISABLE => ['label' => FontIcon::i('fa-unlock fa-2x fa-fw') . Yii::t('hipanel', 'Disable block'), 'position' => ModalButton::BUTTON_OUTSIDE]], $this->button);
         $this->button = $this->button[$this->action];
     }
     if (is_array($this->header)) {
         $this->header = ArrayHelper::merge([static::ACTION_ENABLE => ['label' => Yii::t('hipanel', 'Are you sure you want to block this object'), 'class' => 'label-danger'], static::ACTION_DISABLE => ['label' => Yii::t('hipanel', 'Are you sure you want to unblock this object'), 'class' => 'label-info']], $this->header);
         $this->header = $this->header[$this->action];
     }
     if (is_array($this->warning)) {
         $this->warning = ArrayHelper::merge([static::ACTION_ENABLE => false, static::ACTION_DISABLE => ['label' => Yii::t('hipanel', 'Check whether all of the violations were eliminated')]], $this->warning);
         $this->warning = $this->warning[$this->action];
     }
     if (is_array($this->footer)) {
         $this->footer = ArrayHelper::merge([static::ACTION_ENABLE => ['label' => Yii::t('hipanel', 'Enable block'), 'data-loading-text' => Yii::t('hipanel', 'loading...'), 'class' => 'btn btn-danger'], static::ACTION_DISABLE => ['label' => Yii::t('hipanel', 'Disable block'), 'data-loading-text' => Yii::t('hipanel', 'loading...'), 'class' => 'btn btn-info']], $this->footer);
         $this->footer = $this->footer[$this->action];
     }
 }
 public static function pdfLink($file, $month = 'now')
 {
     return Html::a(FontIcon::i('fa-file-pdf-o fa-2x') . date(' M Y', strtotime($month)), ["/file/{$file->id}/{$file->filename}", 'nocache' => 1], ['target' => '_blank', 'class' => 'text-info text-nowrap col-xs-6 col-sm-6 col-md-6 col-lg-3']);
 }