1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
datefield.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\ORM\Fields;
10
11use Bitrix\Main;
12use Bitrix\Main\ArgumentException;
13use Bitrix\Main\ArgumentTypeException;
14use Bitrix\Main\DB\SqlExpression;
15use Bitrix\Main\Type;
16use Bitrix\Main\Type\Date;
17
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 {
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(
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}
configureFormat($format)
Определения datefield.php:42
__construct($name, $parameters=array())
Определения datefield.php:35
assureValueObject($value)
Определения datefield.php:72
convertValueFromDb($value)
Определения datefield.php:114
convertValueToDb($value)
Определения datefield.php:126
getConnection()
Определения field.php:638
addFetchDataModifier($modifier)
Определения field.php:351
getNullableTypeHint(string $type)
Определения scalarfield.php:301
Определения date.php:9
const MULTIPLE_DATE_FORMAT
Определения userfield.php:35
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения collection.php:2