Passed
Push — master ( 7ba57e...634515 )
by Paweł
03:13
created

TagColumn::getDataCellValue()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nc 8
nop 3
dl 0
loc 22
rs 9.4888
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 16.08.2018
6
 */
7
8
namespace app\modules\admin\components\grid;
9
10
11
use app\dictionaries\TagInvalidationType;
12
use jakim\ig\Url;
13
use yii\grid\DataColumn;
14
use yii\helpers\Html;
15
16
class TagColumn extends DataColumn
17
{
18
    public $format = 'raw';
19
    public $displayDashboardLink = false;
20
21
    public function getDataCellValue($model, $key, $index)
22
    {
23
        $html = [];
24
        if ($this->displayDashboardLink || $model->monitoring) {
25
            $html[] = Html::a($model->namePrefixed, ['tag/stats', 'id' => $model->id]);
26
        } else {
27
            $html[] = $model->{$this->attribute};
28
        }
29
        $html[] = Html::a('<span class="fa fa-external-link text-sm"></span>', Url::tag($model->name), ['target' => '_blank']);
30
31
        if (!$model->is_valid) {
32
            $html[] = sprintf(
33
                '<span class="fa fa-exclamation-triangle text-danger pull-right" data-toggle="tooltip" data-placement="top"  title="%s, attempts: %s"></span>',
34
                TagInvalidationType::getLabel($model->invalidation_type_id, 'Unknown reason'),
35
                $model->invalidation_count
36
            );
37
        }
38
        if ($model->disabled) {
39
            $html[] = '<span class="fa fa-exclamation-triangle text-danger pull-right" title="Not found."></span>';
40
        }
41
42
        return implode(" \n", $html);
43
    }
44
}