ColspanColumn   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 52
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 14 4
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\grid;
12
13
use Yii;
14
use yii\grid\Column;
15
use yii\helpers\Html;
16
17
/**
18
 * Class ColspanColumn.
19
 *
20
 * @author Dmytro Naumenko <[email protected]>
21
 */
22
class ColspanColumn extends DataColumn
23
{
24
    /** @var Column[] */
25
    public $columns;
26
27
    public function init()
28
    {
29
        $this->headerOptions['colspan'] = count($this->columns);
30
        parent::init();
31
    }
32
33
    public function renderDataCell($model, $key, $index)
34
    {
35
        $cells = [];
36
37
        foreach ($this->createSubColumns() as $column) {
38
            $cells[] = $column->renderDataCell($model, $key, $index);
39
        }
40
41
        return implode('', $cells);
42
    }
43
44
    public function renderFilterCell()
45
    {
46
        $cells = [];
47
48
        foreach ($this->createSubColumns() as $column) {
49
            $cells[] = Html::tag('td', $column->renderHeaderCellContent(), $this->filterOptions);
50
        }
51
52
        return implode('', $cells);
53
    }
54
55
    /**
56
     * @throws \yii\base\InvalidConfigException
57
     * @return Column[]
58
     */
59
    protected function createSubColumns()
60
    {
61
        foreach ($this->columns as $id => $column) {
62
            if ($column instanceof Column) {
63
                continue;
64
            }
65
            $this->columns[$id] = Yii::createObject(array_merge([
66
                'class' => $this->grid->dataColumnClass ?: DataColumn::class,
67
                'grid' => $this->grid,
68
            ], $column));
69
        }
70
71
        return $this->columns;
72
    }
73
}
74