1 | <?php |
||
2 | |||
3 | namespace hipanel\modules\server\grid; |
||
4 | |||
5 | use hipanel\helpers\StringHelper; |
||
6 | use hipanel\modules\server\models\Binding; |
||
7 | use Yii; |
||
8 | use yii\grid\DataColumn; |
||
9 | use yii\helpers\Html; |
||
10 | |||
11 | class BindingColumn extends DataColumn |
||
12 | { |
||
13 | public $format = 'raw'; |
||
14 | |||
15 | public $filter = false; |
||
16 | |||
17 | public function init() |
||
18 | { |
||
19 | parent::init(); |
||
20 | $this->visible = Yii::$app->user->can('hub.read'); |
||
0 ignored issues
–
show
|
|||
21 | $this->label = $this->getLabel(); |
||
22 | } |
||
23 | |||
24 | public function getDataCellValue($model, $key, $index) |
||
25 | { |
||
26 | if (StringHelper::startsWith($this->attribute, 'ipmi', false) && ($ipmi = $model->getBinding($this->attribute)) !== null) { |
||
27 | $link = Html::a($ipmi->device_ip, "http://$ipmi->device_ip/", ['target' => '_blank']) . ' '; |
||
28 | |||
29 | return $link . $this->renderSwitchPort($ipmi); |
||
30 | } |
||
31 | |||
32 | return $this->renderSwitchPort($model->bindings[$this->attribute]); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param Binding|null $binding |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function renderSwitchPort(?Binding $binding): string |
||
40 | { |
||
41 | if ($binding === null) { |
||
42 | return ''; |
||
43 | } |
||
44 | |||
45 | $label = $binding->switch_label; |
||
46 | $inn = $binding->switch_inn; |
||
47 | $inn = $inn ? "($inn) " : ''; |
||
48 | $main = $binding->switch . ($binding->port ? ':' . $binding->port : ''); |
||
49 | |||
50 | return "$inn<b>$main</b> $label"; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | private function getLabel(): string |
||
57 | { |
||
58 | $defaultLabel = $this->getHeaderCellLabel(); |
||
59 | $addColon = preg_replace('/(\d+)/', ':${1}', $defaultLabel); |
||
60 | $replaceName = preg_replace(['/Net/', '/Pdu/'], ['Switch', 'APC'], $addColon); |
||
61 | |||
62 | return (string)$replaceName; |
||
63 | } |
||
64 | } |
||
65 |
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.