Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
datefield.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields
;
10
11
use
Bitrix\Main
;
12
use
Bitrix\Main\ArgumentException
;
13
use
Bitrix\Main\ArgumentTypeException
;
14
use
Bitrix\Main\DB\SqlExpression
;
15
use
Bitrix\Main\Type
;
16
use
Bitrix\Main\Type\Date
;
17
23
class
DateField
extends
ScalarField
24
{
25
protected
$format
=
null
;
26
35
public
function
__construct
(
$name
, $parameters = array())
36
{
37
parent::__construct(
$name
, $parameters);
38
39
$this->
addFetchDataModifier
(array($this,
'assureValueObject'
));
40
}
41
42
public
function
configureFormat
(
$format
)
43
{
44
$this->format =
$format
;
45
46
return
$this;
47
}
48
54
public
function
getValidators
()
55
{
56
$validators
= parent::getValidators();
57
58
if
($this->validation ===
null
)
59
{
60
$validators
[] =
new
Validators\DateValidator
;
61
}
62
63
return
$validators
;
64
}
65
72
public
function
assureValueObject
($value)
73
{
74
if
($value instanceof
Type
\
DateTime
)
75
{
76
// oracle sql helper returns datetime instead of date - it doesn't see the difference
77
$value =
new
Type\Date
(
78
$value->format(Main\
UserFieldTable::MULTIPLE_DATE_FORMAT
),
79
Main\
UserFieldTable::MULTIPLE_DATE_FORMAT
80
);
81
}
82
83
return
$value;
84
}
85
92
public
function
cast
($value)
93
{
94
if
($value instanceof
SqlExpression
)
95
{
96
return
$value;
97
}
98
99
if
(!empty($value) && !($value instanceof
Type
\
Date
))
100
{
101
return
new
Type\Date
($value, $this->format);
102
}
103
104
return
$value;
105
}
106
114
public
function
convertValueFromDb
($value)
115
{
116
return
$this->
getConnection
()->getSqlHelper()->convertFromDbDate($value);
117
}
118
126
public
function
convertValueToDb
($value)
127
{
128
if
($value instanceof
SqlExpression
)
129
{
130
return
$value;
131
}
132
133
try
134
{
135
return
$value ===
null
&& $this->is_nullable
136
? $value
137
: $this->
getConnection
()->getSqlHelper()->convertToDbDate($value);
138
}
139
catch
(
ArgumentTypeException
$e)
140
{
141
throw
new
ArgumentException
(
142
"Type error in `{$this->name}` of `{$this->entity->getFullName()}`: "
.$e->getMessage()
143
);
144
}
145
}
146
150
public
function
getGetterTypeHint
()
151
{
152
return
$this->
getNullableTypeHint
(
'\\'
.Date::class);
153
}
154
158
public
function
getSetterTypeHint
()
159
{
160
return
$this->
getNullableTypeHint
(
'\\'
.Date::class);
161
}
162
}
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\DateField\$format
$format
Definition
datefield.php:25
Bitrix\Main\ORM\Fields\DateField\configureFormat
configureFormat($format)
Definition
datefield.php:42
Bitrix\Main\ORM\Fields\DateField\getValidators
getValidators()
Definition
datefield.php:54
Bitrix\Main\ORM\Fields\DateField\getSetterTypeHint
getSetterTypeHint()
Definition
datefield.php:158
Bitrix\Main\ORM\Fields\DateField\cast
cast($value)
Definition
datefield.php:92
Bitrix\Main\ORM\Fields\DateField\__construct
__construct($name, $parameters=array())
Definition
datefield.php:35
Bitrix\Main\ORM\Fields\DateField\getGetterTypeHint
getGetterTypeHint()
Definition
datefield.php:150
Bitrix\Main\ORM\Fields\DateField\assureValueObject
assureValueObject($value)
Definition
datefield.php:72
Bitrix\Main\ORM\Fields\DateField\convertValueFromDb
convertValueFromDb($value)
Definition
datefield.php:114
Bitrix\Main\ORM\Fields\DateField\convertValueToDb
convertValueToDb($value)
Definition
datefield.php:126
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\addFetchDataModifier
addFetchDataModifier($modifier)
Definition
field.php:344
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\DateValidator
Definition
datevalidator.php:15
Bitrix\Main\Type\Date
Definition
date.php:9
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\UserFieldTable\MULTIPLE_DATE_FORMAT
const MULTIPLE_DATE_FORMAT
Definition
userfield.php:37
Bitrix\Main\ORM\Fields
Definition
arrayfield.php:9
Bitrix\Main\Type
Definition
collection.php:2
Bitrix\Main
modules
main
lib
orm
fields
datefield.php
Создано системой
1.10.0