Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
datefield.php
1<?php
10
11use Bitrix\Main;
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(
78 $value->format(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}
__construct($name, $parameters=array())
Definition datefield.php:35
addFetchDataModifier($modifier)
Definition field.php:344