LogActionColumn   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 15
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDataCellValue() 0 8 1
1
<?php
2
namespace backend\components\grid;
3
4
use yii\helpers\Html;
5
use yii\helpers\ArrayHelper;
6
use backend\models\Log;
7
use yii\grid\DataColumn;
8
9
class LogActionColumn extends DataColumn
10
{
11
    const LABEL_DEFAULT = 'label label-primary';
12
    const LABEL_LOGIN = 'label label-default';
13
    const LABEL_DELETE = 'label label-warning';
14
    const LABEL_CREATE = 'label label-success';
15
16
    protected $actionIconsMap = [
17
        Log::ACTION_LOGIN => self::LABEL_LOGIN,
18
        Log::ACTION_LOGOUT => self::LABEL_LOGIN,
19
        Log::ACTION_CREATE => self::LABEL_CREATE,
20
        Log::ACTION_DELETE => self::LABEL_DELETE,
21
    ];
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getDataCellValue($model, $key = null, $index = null)
27
    {
28
        $value = parent::getDataCellValue($model, $key, $index);
29
        return Html::tag(
30
            'span',
31
            ArrayHelper::getValue(Log::listActions(), $value),
32
            [
33
                'class' => ArrayHelper::getValue($this->actionIconsMap, $value, self::LABEL_DEFAULT),
34
            ]
35
        );
36
    }
37
}
38