Completed
Push — master ( ad7826...7e4c9e )
by Dmitry
06:01
created

ColspanColumn   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
A renderDataCell() 0 10 2
A renderFilterCell() 0 10 2
A createSubColumns() 0 13 4
1
<?php
2
3
namespace hipanel\grid;
4
5
use Yii;
6
use yii\grid\Column;
7
use yii\helpers\Html;
8
9
/**
10
 * Class ColspanColumn
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class ColspanColumn extends DataColumn
15
{
16
    /** @var Column[] */
17
    public $columns;
18
19
    public function init()
20
    {
21
        $this->headerOptions['colspan'] = count($this->columns);
22
        parent::init();
23
    }
24
25
    public function renderDataCell($model, $key, $index)
26
    {
27
        $cells = [];
28
29
        foreach ($this->createSubColumns() as $column) {
30
            $cells[] = $column->renderDataCell($model, $key, $index);
31
        }
32
33
        return implode('', $cells);
34
    }
35
36
    public function renderFilterCell()
37
    {
38
        $cells = [];
39
40
        foreach ($this->createSubColumns() as $column) {
41
            $cells[] = Html::tag('td', $column->renderHeaderCellContent(), $this->filterOptions);
42
        }
43
44
        return implode('', $cells);
45
    }
46
47
    /**
48
     * @return Column[]
49
     * @throws \yii\base\InvalidConfigException
50
     */
51
    protected function createSubColumns()
52
    {
53
        foreach ($this->columns as $id => $column) {
54
            if ($column instanceof Column) {
55
                continue;
56
            }
57
            $this->columns[$id] = Yii::createObject(array_merge([
58
                'class' => $this->grid->dataColumnClass ?: DataColumn::className(),
59
                'grid' => $this->grid,
60
            ], $column));
61
        }
62
        return $this->columns;
63
    }
64
}
65