Completed
Push — master ( d3d4f1...87596f )
by Klochok
05:46
created

BlockingColumn::init()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace hipanel\grid;
4
5
use Exception;
6
use hipanel\widgets\ClientSellerLink;
7
use Yii;
8
9
class BlockingColumn extends \hiqdev\higrid\DataColumn
10
{
11
    public function init()
12
    {
13
        try {
14
            $this->visible = reset($this->grid->dataProvider->getModels())->blocking->reason;
0 ignored issues
show
Bug introduced by
$this->grid->dataProvider->getModels() cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
15
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
16
17
        } finally {
18
            parent::init();
19
        }
20
    }
21
22
    protected
23
    function renderDataCellContent($model, $key, $index)
24
    {
25
        $html = '';
26
        if ($model->blocking && $model->blocking->reason) {
27
            $reasonLabel = Yii::t('hipanel:block-reasons', $model->blocking->reason_label);
28
            $time = Yii::$app->formatter->asDate($model->blocking->time);
29
            $clientSellerLink = $model->blocking->client_id ? ClientSellerLink::widget(['model' => $model->blocking]) : '';
30
            $html = <<<HTML
31
                <div>
32
                    <small class="pull-right text-warning">{$time}</small>
33
                    <strong>{$reasonLabel}</strong>
34
                    <div>{$model->blocking->comment}</div>
35
                    <small class="text-muted">{$clientSellerLink}</small>
36
                </div>
37
HTML;
38
        }
39
40
        return $html;
41
    }
42
}
43