Completed
Push — master ( 793680...1bd5c4 )
by Dmitry
32:18 queued 17:08
created

HubGridView::formatTariff()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\grid;
12
13
use hipanel\grid\MainColumn;
14
use hipanel\grid\RefColumn;
15
use hipanel\modules\client\grid\ClientColumn;
16
use hipanel\modules\server\menus\HubActionsMenu;
17
use hipanel\widgets\gridLegend\ColorizeGrid;
18
use hiqdev\yii2\menus\grid\MenuColumn;
19
use Yii;
20
use yii\helpers\Html;
21
22
class HubGridView extends \hipanel\grid\BoxedGridView
23
{
24
    use ColorizeGrid;
0 ignored issues
show
introduced by
The trait hipanel\widgets\gridLegend\ColorizeGrid requires some properties which are not provided by hipanel\modules\server\grid\HubGridView: $controller, $module
Loading history...
25
26
    protected function formatTariff($model): string
27
    {
28
        if (Yii::$app->user->can('plan.read')) {
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

28
        if (Yii::$app->user->/** @scrutinizer ignore-call */ can('plan.read')) {

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...
29
            if ($model->parent_tariff) {
30
                $title = Html::tag('abbr', $model->parent_tariff, [
31
                    'title' => $model->tariff, 'data-toggle' => 'tooltip',
32
                ]);
33
            } else {
34
                $title = $model->tariff;
35
            }
36
37
            return Html::a($title, ['@plan/view', 'id' => $model->tariff_id]);
38
        }
39
40
        return !empty($model->parent_tariff) ? $model->parent_tariff : $model->tariff;
41
    }
42
43
    public function columns()
44
    {
45
        return array_merge(parent::columns(), [
46
            'inn' => [
47
                'enableSorting' => false,
48
                'filterOptions' => ['class' => 'narrow-filter'],
49
            ],
50
            'model' => [
51
                'enableSorting' => false,
52
                'filterOptions' => ['class' => 'narrow-filter'],
53
            ],
54
            'ip' => [
55
                'enableSorting' => false,
56
                'filterOptions' => ['class' => 'narrow-filter'],
57
            ],
58
            'mac' => [
59
                'enableSorting' => false,
60
                'filterOptions' => ['class' => 'narrow-filter'],
61
            ],
62
            'actions' => [
63
                'class' => MenuColumn::class,
64
                'menuClass' => HubActionsMenu::class,
65
            ],
66
            'traf_server_id' => [
67
                'format' => 'html',
68
                'enableSorting' => false,
69
                'value' => function ($model) {
70
                    return Html::a($model->traf_server_id_label, ['@server/view', 'id' => $model->traf_server_id]);
71
                },
72
            ],
73
            'vlan_server_id' => [
74
                'format' => 'html',
75
                'enableSorting' => false,
76
                'value' => function ($model) {
77
                    return Html::a($model->vlan_server_id_label, ['@server/view', 'id' => $model->vlan_server_id]);
78
                },
79
            ],
80
            'buyer' => [
81
                'label' => Yii::t('hipanel:server:hub', 'Buyer'),
82
                'class' => ClientColumn::class,
83
                'idAttribute' => 'buyer_id',
84
                'attribute' => 'buyer_id',
85
                'nameAttribute' => 'buyer',
86
                'enableSorting' => false,
87
            ],
88
            'switch' => [
89
                'class' => MainColumn::class,
90
                'attribute' => 'name',
91
                'filterAttribute' => 'name_ilike',
92
                'note' => 'note',
93
            ],
94
            'type' => [
95
                'class' => RefColumn::class,
96
                'filterOptions' => ['class' => 'narrow-filter'],
97
                'enableSorting' => false,
98
                'findOptions' => [
99
                    'select' => 'full',
100
                    'mapOptions' => ['from' => 'id', 'to' => 'label'],
101
                ],
102
                'attribute' => 'type_id',
103
                'i18nDictionary' => 'hipanel:server:hub',
104
                'gtype' => 'type,device,switch',
105
                'value' => function ($model) {
106
                    return Yii::t('hipanel:server:hub', $model->type_label);
107
                },
108
            ],
109
            'tariff' => [
110
                'format' => 'raw',
111
                'filterAttribute' => 'tariff_like',
112
                'value' => function ($model): string {
113
                    return $this->formatTariff($model);
114
                },
115
            ],
116
            'sale_time' => [
117
                'attribute' => 'sale_time',
118
                'format' => 'datetime',
119
            ],
120
        ]);
121
    }
122
}
123