Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
booleanfield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
11
use
Bitrix\Main\DB\SqlExpression
;
12
19
class
BooleanField
extends
ScalarField
20
{
25
protected
$values
;
26
35
function
__construct
(
$name
, $parameters = array())
36
{
37
parent::__construct(
$name
, $parameters);
38
39
if
(empty($parameters[
'values'
]))
40
{
41
$this->values = array(
false
,
true
);
42
}
43
else
44
{
45
$this->values = $parameters[
'values'
];
46
}
47
48
$this->
addSaveDataModifier
(array($this,
'normalizeValue'
));
49
}
50
57
public
function
configureStorageValues
($falseValue, $trueValue)
58
{
59
$this->values = [$falseValue, $trueValue];
60
return
$this;
61
}
62
71
public
function
configureValues
($falseValue, $trueValue)
72
{
73
return
$this->
configureStorageValues
($falseValue, $trueValue);
74
}
75
81
public
function
normalizeValue
($value)
82
{
83
if
(
84
(is_string($value) && ($value ==
'1'
|| $value ==
'0'
))
85
||
86
(is_bool($value))
87
)
88
{
89
$value = (int) $value;
90
}
91
elseif (is_string($value) && $value ==
'true'
)
92
{
93
$value = 1;
94
}
95
elseif (is_string($value) && $value ==
'false'
)
96
{
97
$value = 0;
98
}
99
100
if
(is_integer($value) && ($value == 1 || $value == 0))
101
{
102
$value = $this->values[$value];
103
}
104
105
return
$value;
106
}
107
115
public
function
booleanizeValue
($value)
116
{
117
if
(is_bool($value))
118
{
119
return
$value;
120
}
121
122
$normalizedValue = $this->
normalizeValue
($value);
123
return
(
bool
) array_search($normalizedValue, $this->values,
true
);
124
}
125
131
public
function
getValidators
()
132
{
133
$validators
= parent::getValidators();
134
135
if
($this->validation ===
null
)
136
{
137
$validators
[] =
new
Validators\BooleanValidator
;
138
}
139
140
return
$validators
;
141
}
142
143
public
function
getValues
()
144
{
145
return
$this->values
;
146
}
147
148
public
function
isValueEmpty
($value)
149
{
150
return
(strval($value) ===
''
&& $value !==
false
);
151
}
152
158
public
function
cast
($value)
159
{
160
if
($this->is_nullable && $value ===
null
)
161
{
162
return
$value;
163
}
164
165
if
($value instanceof
SqlExpression
)
166
{
167
return
$value;
168
}
169
170
return
$this->
booleanizeValue
($value);
171
}
172
178
public
function
convertValueFromDb
($value)
179
{
180
return
$this->
booleanizeValue
($value);
181
}
182
189
public
function
convertValueToDb
($value)
190
{
191
if
($value instanceof
SqlExpression
)
192
{
193
return
$value;
194
}
195
196
return
$value ===
null
&& $this->is_nullable
197
? $value
198
: $this->
getConnection
()->getSqlHelper()->convertToDbString(
199
$this->
normalizeValue
($value)
200
);
201
}
202
206
public
function
getGetterTypeHint
()
207
{
208
return
$this->
getNullableTypeHint
(
'\\boolean'
);
209
}
210
214
public
function
getSetterTypeHint
()
215
{
216
return
$this->
getNullableTypeHint
(
'\\boolean'
);
217
}
218
}
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Main\ORM\Fields\BooleanField
Definition
booleanfield.php:20
Bitrix\Main\ORM\Fields\BooleanField\configureStorageValues
configureStorageValues($falseValue, $trueValue)
Definition
booleanfield.php:57
Bitrix\Main\ORM\Fields\BooleanField\configureValues
configureValues($falseValue, $trueValue)
Definition
booleanfield.php:71
Bitrix\Main\ORM\Fields\BooleanField\getValidators
getValidators()
Definition
booleanfield.php:131
Bitrix\Main\ORM\Fields\BooleanField\normalizeValue
normalizeValue($value)
Definition
booleanfield.php:81
Bitrix\Main\ORM\Fields\BooleanField\getSetterTypeHint
getSetterTypeHint()
Definition
booleanfield.php:214
Bitrix\Main\ORM\Fields\BooleanField\cast
cast($value)
Definition
booleanfield.php:158
Bitrix\Main\ORM\Fields\BooleanField\getValues
getValues()
Definition
booleanfield.php:143
Bitrix\Main\ORM\Fields\BooleanField\__construct
__construct($name, $parameters=array())
Definition
booleanfield.php:35
Bitrix\Main\ORM\Fields\BooleanField\getGetterTypeHint
getGetterTypeHint()
Definition
booleanfield.php:206
Bitrix\Main\ORM\Fields\BooleanField\booleanizeValue
booleanizeValue($value)
Definition
booleanfield.php:115
Bitrix\Main\ORM\Fields\BooleanField\convertValueFromDb
convertValueFromDb($value)
Definition
booleanfield.php:178
Bitrix\Main\ORM\Fields\BooleanField\isValueEmpty
isValueEmpty($value)
Definition
booleanfield.php:148
Bitrix\Main\ORM\Fields\BooleanField\convertValueToDb
convertValueToDb($value)
Definition
booleanfield.php:189
Bitrix\Main\ORM\Fields\BooleanField\$values
$values
Definition
booleanfield.php:25
Bitrix\Main\ORM\Fields\Field\$name
$name
Definition
field.php:27
Bitrix\Main\ORM\Fields\Field\$validators
$validators
Definition
field.php:42
Bitrix\Main\ORM\Fields\Field\getConnection
getConnection()
Definition
field.php:626
Bitrix\Main\ORM\Fields\Field\addSaveDataModifier
addSaveDataModifier($modifier)
Definition
field.php:420
Bitrix\Main\ORM\Fields\ScalarField
Definition
scalarfield.php:19
Bitrix\Main\ORM\Fields\ScalarField\getNullableTypeHint
getNullableTypeHint(string $type)
Definition
scalarfield.php:255
Bitrix\Main\ORM\Fields\Validators\BooleanValidator
Definition
booleanvalidator.php:19
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
modules
main
lib
orm
fields
booleanfield.php
Создано системой
1.10.0