AbstractNameBadge::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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\widgets;
12
13
use hipanel\modules\server\forms\HubSellForm;
14
use hipanel\modules\server\models\Hub;
15
use hipanel\modules\server\models\Server;
16
use hipanel\widgets\gridLegend\GridLegend;
17
use yii\base\Widget;
18
19
abstract class AbstractNameBadge extends Widget
20
{
21
    /**
22
     * @var string
23
     */
24
    public $gridLegendClass;
25
26
    /**
27
     * @var string
28
     */
29
    public $nameAttribute = 'name';
30
31
    /**
32
     * @var Hub|Server|HubSellForm
33
     */
34
    public $model;
35
36
    public function run()
37
    {
38
        $color = GridLegend::create(new $this->gridLegendClass($this->model))->gridColumnOptions('actions');
39
        $colorString = implode(';', $color);
40
41
        $this->view->registerCss('.badge .item-badge-text { color: #bbbbbb; mix-blend-mode: difference; }');
42
43
        return <<<HTML
44
<span class="badge" style="$colorString"><span class="item-badge-text">{$this->model->{$this->nameAttribute}}</span></span>
45
HTML;
46
    }
47
}
48