Completed
Push — master ( 675c3f...4830ba )
by wen
11:40
created

Checkbox::prepareValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
class Checkbox extends Select
6
{
7
    protected $type = 'checkbox';
8
9
    protected $defaultValue = [];
10
11
    protected $max;
12
    protected $min          = 0;
13
    protected $showCheckAll = false;
14
15
    public function getMax()
16
    {
17
        return $this->max;
18
    }
19
20
    public function setMax($value)
21
    {
22
        $this->max = (int)$value;
23
24
        $this->addValidationRule('max:' . $value);
25
26
        return $this;
27
    }
28
29
    public function getMin()
30
    {
31
        return $this->min;
32
    }
33
34
    public function setMin($value)
35
    {
36
        $this->min = (int)$value;
37
38
        $this->addValidationRule('min:' . $value);
39
40
        return $this;
41
    }
42
43
    public function isShowCheckAll()
44
    {
45
        return $this->showCheckAll;
46
    }
47
48
    public function enableShowCheckAll()
49
    {
50
        $this->showCheckAll = true;
51
52
        return $this;
53
    }
54
55
    public function getValue()
56
    {
57
        $value = parent::getValue();
58
        if (empty($value)) {
59
            return [];
60
        }
61
        return explode(',', $value);
62
    }
63
64
    public function toArray()
65
    {
66
        return parent::toArray() + [
67
                'min'          => $this->getMin(),
68
                'max'          => $this->getMax(),
69
                'showCheckAll' => $this->isShowCheckAll(),
70
            ];
71
    }
72
}
73