SwitchColumn::getDataCellValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
cc 1
nc 1
nop 3
crap 2
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 hipanel\widgets\SwitchInput;
14
use yii\helpers\ArrayHelper;
15
16
class SwitchColumn extends DataColumn
17
{
18
    /** {@inheritdoc} */
19
    public $format = 'raw';
20
21
    /** @var boolean Filtering is disabled for SwitchColumn */
22
    public $filter = false;
23
24
    /** @var array pluginOptions for widget */
25
    public $pluginOptions = [];
26
27
    /** {@inheritdoc} */
28
    public $defaultOptions = [
29
        'pluginOptions' => [
30
            'size' => 'mini',
31
        ],
32
    ];
33
34
    /**
35
     * @var array options that will be passed to [[SwitchInput]] widget
36
     */
37
    public $switchInputOptions = [];
38
39
    public function getDataCellValue($model, $key, $index)
40
    {
41
        return SwitchInput::widget([
42
            'name' => 'swc' . $key . $model->id,
43
            'clientOptions' => ArrayHelper::merge([
44
                'state' => (bool) parent::getDataCellValue($model, $key, $index),
45
            ], $this->pluginOptions, $this->switchInputOptions),
46
        ]);
47
    }
48
}
49