| 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\grid; |
||||
| 12 | |||||
| 13 | use hipanel\grid\BoxedGridView; |
||||
| 14 | use hipanel\grid\MainColumn; |
||||
| 15 | use hipanel\grid\RefColumn; |
||||
| 16 | use hipanel\modules\client\grid\ClientColumn; |
||||
| 17 | use hipanel\modules\server\menus\HubActionsMenu; |
||||
| 18 | use hipanel\modules\server\models\Hub; |
||||
| 19 | use hipanel\widgets\gridLegend\ColorizeGrid; |
||||
| 20 | use hiqdev\yii2\menus\grid\MenuColumn; |
||||
| 21 | use Yii; |
||||
| 22 | use yii\helpers\Html; |
||||
| 23 | |||||
| 24 | class HubGridView extends BoxedGridView |
||||
| 25 | { |
||||
| 26 | use ColorizeGrid; |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @var array |
||||
| 30 | */ |
||||
| 31 | public $extraOptions = []; |
||||
| 32 | |||||
| 33 | public function columns() |
||||
| 34 | { |
||||
| 35 | $extraColumns = []; |
||||
| 36 | foreach (['snmp_version_id', 'digit_capacity_id', 'nic_media'] as $attribute) { |
||||
| 37 | $extraColumns[$attribute] = [ |
||||
| 38 | 'attribute' => $attribute, |
||||
| 39 | 'enableSorting' => false, |
||||
| 40 | 'value' => function (Hub $hub) use ($attribute): ?string { |
||||
| 41 | if ($hub->{$attribute}) { |
||||
| 42 | return $this->extraOptions[$attribute][$hub->{$attribute}]; |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | return null; |
||||
| 46 | } |
||||
| 47 | ]; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | return array_merge(parent::columns(), $extraColumns, [ |
||||
| 51 | 'inn' => [ |
||||
| 52 | 'enableSorting' => false, |
||||
| 53 | 'filterOptions' => ['class' => 'narrow-filter'], |
||||
| 54 | 'filterAttribute' => 'inn_ilike', |
||||
| 55 | ], |
||||
| 56 | 'model' => [ |
||||
| 57 | 'enableSorting' => false, |
||||
| 58 | 'filterOptions' => ['class' => 'narrow-filter'], |
||||
| 59 | ], |
||||
| 60 | 'ip' => [ |
||||
| 61 | 'enableSorting' => false, |
||||
| 62 | 'filterOptions' => ['class' => 'narrow-filter'], |
||||
| 63 | ], |
||||
| 64 | 'mac' => [ |
||||
| 65 | 'enableSorting' => false, |
||||
| 66 | 'filterOptions' => ['class' => 'narrow-filter'], |
||||
| 67 | ], |
||||
| 68 | 'actions' => [ |
||||
| 69 | 'class' => MenuColumn::class, |
||||
| 70 | 'menuClass' => HubActionsMenu::class, |
||||
| 71 | ], |
||||
| 72 | 'traf_server_id' => [ |
||||
| 73 | 'format' => 'html', |
||||
| 74 | 'enableSorting' => false, |
||||
| 75 | 'value' => function ($model) { |
||||
| 76 | return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]); |
||||
| 77 | }, |
||||
| 78 | ], |
||||
| 79 | 'vlan_server_id' => [ |
||||
| 80 | 'format' => 'html', |
||||
| 81 | 'enableSorting' => false, |
||||
| 82 | 'value' => function ($model) { |
||||
| 83 | return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]); |
||||
| 84 | }, |
||||
| 85 | ], |
||||
| 86 | 'buyer' => [ |
||||
| 87 | 'label' => Yii::t('hipanel:server:hub', 'Buyer'), |
||||
| 88 | 'class' => ClientColumn::class, |
||||
| 89 | 'idAttribute' => 'buyer_id', |
||||
| 90 | 'attribute' => 'buyer_id', |
||||
| 91 | 'nameAttribute' => 'buyer', |
||||
| 92 | 'enableSorting' => false, |
||||
| 93 | ], |
||||
| 94 | 'switch' => [ |
||||
| 95 | 'class' => MainColumn::class, |
||||
| 96 | 'attribute' => 'name', |
||||
| 97 | 'filterAttribute' => 'name_ilike', |
||||
| 98 | 'note' => 'note', |
||||
| 99 | ], |
||||
| 100 | 'type' => [ |
||||
| 101 | 'class' => RefColumn::class, |
||||
| 102 | 'filterOptions' => ['class' => 'narrow-filter'], |
||||
| 103 | 'enableSorting' => false, |
||||
| 104 | 'findOptions' => [ |
||||
| 105 | 'select' => 'full', |
||||
| 106 | 'mapOptions' => ['from' => 'id', 'to' => 'label'], |
||||
| 107 | ], |
||||
| 108 | 'attribute' => 'type_id', |
||||
| 109 | 'i18nDictionary' => 'hipanel:server:hub', |
||||
| 110 | 'gtype' => 'type,device,switch', |
||||
| 111 | 'value' => function ($model) { |
||||
| 112 | return Yii::t('hipanel:server:hub', $model->type_label); |
||||
| 113 | }, |
||||
| 114 | ], |
||||
| 115 | 'tariff' => [ |
||||
| 116 | 'format' => 'raw', |
||||
| 117 | 'filterAttribute' => 'tariff_like', |
||||
| 118 | 'value' => function (Hub $model): ?string { |
||||
| 119 | return Yii::$app->user->can('plan.read') |
||||
|
0 ignored issues
–
show
The method
can() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 120 | ? Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id]) |
||||
|
0 ignored issues
–
show
The property
tariff_id does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
The property
tariff does not exist on hipanel\modules\server\models\Hub. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 121 | : $model->tariff; |
||||
| 122 | }, |
||||
| 123 | ], |
||||
| 124 | 'sale_time' => [ |
||||
| 125 | 'attribute' => 'sale_time', |
||||
| 126 | 'format' => 'datetime', |
||||
| 127 | ], |
||||
| 128 | 'order_no' => [ |
||||
| 129 | 'attribute' => 'order_no', |
||||
| 130 | 'filterAttribute' => 'order_no_ilike', |
||||
| 131 | 'enableSorting' => false, |
||||
| 132 | ], |
||||
| 133 | ]); |
||||
| 134 | } |
||||
| 135 | } |
||||
| 136 |