EnumColumn::getDataCellValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
namespace backend\components\grid;
3
4
use yii\grid\DataColumn;
5
use yii\helpers\ArrayHelper;
6
7
class EnumColumn extends DataColumn
8
{
9
    /**
10
     * @var array List of value => name pairs
11
     */
12
    public $enum = [];
13
14
    /**
15
     * @var bool
16
     */
17
    public $loadFilterDefaultValues = true;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function init()
23
    {
24
        if ($this->loadFilterDefaultValues && $this->filter === null) {
25
            $this->filter = $this->enum;
26
        }
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getDataCellValue($model, $key, $index)
33
    {
34
        $value = parent::getDataCellValue($model, $key, $index);
35
        return ArrayHelper::getValue($this->enum, $value, $value);
36
    }
37
}
38