AccountColumn::init()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 5
nop 0
crap 20
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\grid;
12
13
use hipanel\modules\hosting\widgets\combo\AccountCombo;
14
use hiqdev\higrid\DataColumn;
15
use yii\helpers\Html;
16
17
class AccountColumn extends DataColumn
18
{
19
    public $attribute = 'account_id';
20
21
    public $nameAttribute = 'account';
22
23
    public $format = 'html';
24
25
    public function init()
26
    {
27
        parent::init();
28
29
        if (!empty($this->grid->filterModel)) {
30
            if (!$this->filterInputOptions['id']) {
31
                $this->filterInputOptions['id'] = $this->attribute;
32
            }
33
            if (!$this->filter) {
34
                $this->filter = AccountCombo::widget([
35
                    'attribute'           => $this->attribute,
36
                    'model'               => $this->grid->filterModel,
37
                    'formElementSelector' => 'td',
38
                ]);
39
            }
40
        }
41
    }
42
43
    public function getDataCellValue($model, $key, $index)
44
    {
45
        return Html::a($model->{$this->nameAttribute}, ['@account/view', 'id' => $model->{$this->attribute}]);
46
    }
47
}
48