ServerColumn   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 17
c 2
b 1
f 0
dl 0
loc 27
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataCellValue() 0 3 1
A init() 0 13 4
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\modules\server\widgets\combo\ServerCombo;
14
use hiqdev\higrid\DataColumn;
15
use Yii;
16
use yii\helpers\Html;
17
18
class ServerColumn extends DataColumn
19
{
20
    public $idAttribute = 'server_id';
21
    public $attribute = 'server_id';
22
    public $nameAttribute = 'server';
23
    public $format = 'html';
24
    public $comboClass = ServerCombo::class;
25
26
    public function init()
27
    {
28
        parent::init();
29
        if (!$this->filterInputOptions['id']) {
30
            $this->filterInputOptions['id'] = $this->attribute;
31
        }
32
        if (!$this->filter && $this->grid->filterModel) {
33
            $this->filter = Yii::createObject([
34
                'class' => $this->comboClass,
35
                'attribute'           => $this->attribute,
36
                'model'               => $this->grid->filterModel,
37
                'formElementSelector' => 'td',
38
            ])->run();
39
        }
40
    }
41
42
    public function getDataCellValue($model, $key, $index)
43
    {
44
        return Html::a($model->{$this->nameAttribute}, ['/server/server/view', 'id' => $model->{$this->idAttribute}]);
45
    }
46
}
47