Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
datetimefield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
11
use
Bitrix\Main\ArgumentException
;
12
use
Bitrix\Main\ArgumentTypeException
;
13
use
Bitrix\Main\DB\SqlExpression
;
14
use
Bitrix\Main\Type\DateTime
;
15
21
class
DatetimeField
extends
DateField
22
{
24
protected
$useTimezone
=
true
;
25
34
public
function
__construct
(
$name
, $parameters = array())
35
{
36
ScalarField::__construct
(
$name
, $parameters);
37
}
38
43
public
function
configureUseTimezone
($use =
true
)
44
{
45
$this->useTimezone = (bool) $use;
46
47
return
$this;
48
}
49
53
public
function
getFetchDataModifiers
()
54
{
55
$modifiers = parent::getFetchDataModifiers();
56
57
if
(!$this->useTimezone)
58
{
59
$modifiers[] = [__CLASS__,
'disableTimezoneFetchModifier'
];
60
}
61
62
return
$modifiers;
63
}
64
71
public
function
cast
($value)
72
{
73
if
($value instanceof
SqlExpression
)
74
{
75
return
$value;
76
}
77
78
if
(!empty($value) && !($value instanceof
DateTime
))
79
{
80
$value =
new
DateTime
($value);
81
}
82
83
if
($value instanceof
DateTime
)
84
{
85
$this->useTimezone
86
? $value->enableUserTime()
87
: $value->disableUserTime();
88
}
89
90
return
$value;
91
}
92
100
public
function
convertValueFromDb
($value)
101
{
102
return
$this->
getConnection
()->getSqlHelper()->convertFromDbDateTime($value);
103
}
104
112
public
function
convertValueToDb
($value)
113
{
114
if
($value instanceof
SqlExpression
)
115
{
116
return
$value;
117
}
118
119
try
120
{
121
return
$value ===
null
&& $this->is_nullable
122
? $value
123
: $this->
getConnection
()->getSqlHelper()->convertToDbDateTime($value);
124
}
125
catch
(
ArgumentTypeException
$e)
126
{
127
$exceptionMsg = $this->entity
128
?
"Type error in `{$this->name}` of `{$this->entity->getFullName()}`"
129
:
"Type error in `{$this->name}`"
;
130
131
throw
new
ArgumentException
(
132
"{$exceptionMsg}: {$e->getMessage()}"
133
);
134
}
135
}
136
143
public
static
function
disableTimezoneFetchModifier
($time)
144
{
145
if
($time !==
null
)
146
{
147
$time->disableUserTime();
148
}
149
150
return
$time;
151
}
152
156
public
function
getGetterTypeHint
()
157
{
158
return
$this->
getNullableTypeHint
(
'\\'
.DateTime::class);
159
}
160
164
public
function
getSetterTypeHint
()
165
{
166
return
$this->
getNullableTypeHint
(
'\\'
.DateTime::class);
167
}
168
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ArgumentTypeException
Definition
exception.php:114
Bitrix\Main\DB\SqlExpression
Definition
sqlexpression.php:19
Bitrix\Main\ORM\Fields\DateField
Definition
datefield.php:24
Bitrix\Main\ORM\Fields\DatetimeField
Definition
datetimefield.php:22
Bitrix\Main\ORM\Fields\DatetimeField\configureUseTimezone
configureUseTimezone($use=true)
Definition
datetimefield.php:43
Bitrix\Main\ORM\Fields\DatetimeField\getSetterTypeHint
getSetterTypeHint()
Definition
datetimefield.php:164
Bitrix\Main\ORM\Fields\DatetimeField\getFetchDataModifiers
getFetchDataModifiers()
Definition
datetimefield.php:53
Bitrix\Main\ORM\Fields\DatetimeField\cast
cast($value)
Definition
datetimefield.php:71
Bitrix\Main\ORM\Fields\DatetimeField\__construct
__construct($name, $parameters=array())
Definition
datetimefield.php:34
Bitrix\Main\ORM\Fields\DatetimeField\getGetterTypeHint
getGetterTypeHint()
Definition
datetimefield.php:156
Bitrix\Main\ORM\Fields\DatetimeField\$useTimezone
$useTimezone
Definition
datetimefield.php:24
Bitrix\Main\ORM\Fields\DatetimeField\convertValueFromDb
convertValueFromDb($value)
Definition
datetimefield.php:100
Bitrix\Main\ORM\Fields\DatetimeField\convertValueToDb
convertValueToDb($value)
Definition
datetimefield.php:112
Bitrix\Main\ORM\Fields\DatetimeField\disableTimezoneFetchModifier
static disableTimezoneFetchModifier($time)
Definition
datetimefield.php:143
Bitrix\Main\ORM\Fields\Field\$name
$name
Definition
field.php:27
Bitrix\Main\ORM\Fields\Field\getConnection
getConnection()
Definition
field.php:626
Bitrix\Main\ORM\Fields\ScalarField\__construct
__construct($name, $parameters=array())
Definition
scalarfield.php:47
Bitrix\Main\ORM\Fields\ScalarField\getNullableTypeHint
getNullableTypeHint(string $type)
Definition
scalarfield.php:255
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
modules
main
lib
orm
fields
datetimefield.php
Создано системой
1.10.0