ServerColumn::init()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.9332
cc 4
nc 4
nop 0
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-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