1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.newicon.net/neon |
4
|
|
|
* @copyright Copyright (c) 2016 Newicon Ltd |
5
|
|
|
* @license http://www.newicon.net/neon/license |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace neon\core\form\fields; |
9
|
|
|
|
10
|
|
|
use \neon\core\form\fields\Field; |
11
|
|
|
use \neon\core\helpers\Arr; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Text |
15
|
|
|
* @package neon\core\form |
16
|
|
|
*/ |
17
|
|
|
class Checkbox extends Field |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @inheritdoc |
22
|
|
|
*/ |
23
|
|
|
public $ddsDataType = 'boolean'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The label to display when true |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $trueLabel = 'True'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The label to display when false |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $falseLabel = 'False'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The text to display adjacent to the checkbox |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $_checkboxLabel; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The text to display adjacent to the checkbox |
46
|
|
|
* |
47
|
|
|
* @param $value |
48
|
|
|
* @return $this; |
49
|
|
|
*/ |
50
|
2 |
|
public function setCheckboxLabel($value) |
51
|
|
|
{ |
52
|
2 |
|
$this->_checkboxLabel = $value; |
53
|
2 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the text to display adjacent to the checkbox |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
2 |
|
public function getCheckboxLabel() |
62
|
|
|
{ |
63
|
2 |
|
return $this->_checkboxLabel; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
2 |
|
public function getData() |
70
|
|
|
{ |
71
|
|
|
// The value here is evaluating the user input |
72
|
|
|
// typically this is a string of 0 or 1, however we also support true and false strings |
73
|
|
|
// by using the truthy function a string of 'false' will return as boolean false |
74
|
|
|
// (a normal php if statement would evaluate a string of 'false' as true |
75
|
2 |
|
return truthy($this->getValue()) ? 1 : 0; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritdoc |
80
|
|
|
*/ |
81
|
|
|
public function getValueDisplay($context='') |
82
|
|
|
{ |
83
|
|
|
return $this->getData() ? $this->trueLabel : $this->falseLabel; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritdoc |
88
|
|
|
*/ |
89
|
|
|
public function getFilterField() |
90
|
|
|
{ |
91
|
|
|
return [ |
92
|
|
|
'class' => 'neon\core\form\fields\Select', |
93
|
|
|
'items' => [0 => $this->falseLabel, 1 => $this->trueLabel] |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
2 |
|
public function getProperties() |
101
|
|
|
{ |
102
|
2 |
|
return Arr::merge(parent::getProperties(), ['checkboxLabel']); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
|
|
public function fake() |
109
|
|
|
{ |
110
|
|
|
return faker()->boolean ? 0 : 1; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @inheritdoc |
115
|
|
|
*/ |
116
|
|
|
public function getComponentDetails() |
117
|
|
|
{ |
118
|
|
|
return [ |
119
|
|
|
'label' => 'Checkbox', 'group' => 'Choice', 'icon' => 'fa fa-check-square', 'order' => 440, |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
} |