Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
usertypefield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
use
Bitrix\Main\ArgumentException
;
11
19
class
UserTypeField
extends
ExpressionField
20
{
22
protected
$isMultiple
=
false
;
23
30
public
function
cast
($value)
31
{
32
if
($this->
isMultiple
)
33
{
34
if
($value !==
false
&& $value !==
null
)
// empty value for multiple field
35
{
36
//if (!\is_iterable($value)) PHP 7
37
if
(!is_array($value) && !($value instanceof \Traversable))
38
{
39
throw
new
ArgumentException
(sprintf(
40
'Expected iterable value for multiple field, but got `%s` instead'
, gettype($value)
41
));
42
}
43
44
// array of values
45
foreach
($value as &$_value)
46
{
47
$_value = $this->valueField->getUtmField()->cast($_value);
48
}
49
}
50
51
return
$value;
52
}
53
else
54
{
55
return
parent::cast($value);
56
}
57
}
58
62
public
function
getTypeMask
()
63
{
64
return
FieldTypeMask::USERTYPE
;
65
}
66
72
public
function
configureMultiple
(
$isMultiple
=
true
)
73
{
74
$this->
isMultiple
= (bool)
$isMultiple
;
75
return
$this;
76
}
77
81
public
function
isMultiple
()
82
{
83
return
$this->isMultiple
;
84
}
85
92
public
function
convertValueToDb
($value)
93
{
94
return
$this->
isMultiple
95
? $this->
getConnection
()->getSqlHelper()->convertToDbString($value)
// serialized values
96
: parent::convertValueToDb($value);
97
}
98
99
public
function
getFetchDataModifiers
()
100
{
101
$srcField = $this->
getBuildFromChains
()[0]->getLastElement()->getValue();
102
103
return
array_merge(parent::getFetchDataModifiers(), $srcField->getFetchDataModifiers());
104
}
105
106
public
function
getSaveDataModifiers
()
107
{
108
$srcField = $this->
getBuildFromChains
()[0]->getLastElement()->getValue();
109
110
return
array_merge(parent::getSaveDataModifiers(), $srcField->getSaveDataModifiers());
111
}
112
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\ORM\Fields\ExpressionField\getBuildFromChains
getBuildFromChains()
Definition
expressionfield.php:280
Bitrix\Main\ORM\Fields\Field\getConnection
getConnection()
Definition
field.php:626
Bitrix\Main\ORM\Fields\FieldTypeMask\USERTYPE
const USERTYPE
Definition
fieldtypemask.php:19
Bitrix\Main\ORM\Fields\UserTypeField
Definition
usertypefield.php:20
Bitrix\Main\ORM\Fields\UserTypeField\$isMultiple
$isMultiple
Definition
usertypefield.php:22
Bitrix\Main\ORM\Fields\UserTypeField\getFetchDataModifiers
getFetchDataModifiers()
Definition
usertypefield.php:99
Bitrix\Main\ORM\Fields\UserTypeField\cast
cast($value)
Definition
usertypefield.php:30
Bitrix\Main\ORM\Fields\UserTypeField\configureMultiple
configureMultiple($isMultiple=true)
Definition
usertypefield.php:72
Bitrix\Main\ORM\Fields\UserTypeField\getTypeMask
getTypeMask()
Definition
usertypefield.php:62
Bitrix\Main\ORM\Fields\UserTypeField\getSaveDataModifiers
getSaveDataModifiers()
Definition
usertypefield.php:106
Bitrix\Main\ORM\Fields\UserTypeField\isMultiple
isMultiple()
Definition
usertypefield.php:81
Bitrix\Main\ORM\Fields\UserTypeField\convertValueToDb
convertValueToDb($value)
Definition
usertypefield.php:92
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
modules
main
lib
orm
fields
usertypefield.php
Создано системой
1.10.0