1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
prop_date.php
См. документацию.
1<?php
2
6
8{
11
12 private const INTERNAL_FORMAT = 'YYYY-MM-DD';
13
14 public static function GetUserTypeDescription()
15 {
16 return [
17 'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_STRING,
19 'DESCRIPTION' => Loc::getMessage('IBLOCK_PROP_DATE_DESC'),
20 //optional handlers
21 'GetPublicViewHTML' => [__CLASS__, 'GetPublicViewHTML'],
22 'GetPublicEditHTML' => [__CLASS__, 'GetPublicEditHTML'],
23 'GetPublicEditHTMLMulty' => [__CLASS__, 'GetPublicEditHTMLMulty'],
24 'GetAdminListViewHTML' => [__CLASS__, 'GetAdminListViewHTML'],
25 'GetPropertyFieldHtml' => [__CLASS__, 'GetPropertyFieldHtml'],
26 'CheckFields' => [__CLASS__, 'CheckFields'],
27 'ConvertToDB' => [__CLASS__, 'ConvertToDB'],
28 'ConvertFromDB' => [__CLASS__, 'ConvertFromDB'],
29 'GetSettingsHTML' => [__CLASS__, 'GetSettingsHTML'],
30 'GetAdminFilterHTML' => [__CLASS__, 'GetAdminFilterHTML'],
31 'GetPublicFilterHTML' => [__CLASS__, 'GetPublicFilterHTML'],
32 'AddFilterFields' => [__CLASS__, 'AddFilterFields'],
33 'GetUIFilterProperty' => [__CLASS__, 'GetUIFilterProperty'],
34 'GetUIEntityEditorProperty' => [__CLASS__, 'GetUIEntityEditorProperty'],
35 //"GetORMFields" => array(__CLASS__, "GetORMFields"),
36 ];
37 }
38
46 public static function GetORMFields($valueEntity, $property)
47 {
48 $valueEntity->addField(
49 (new \Bitrix\Main\ORM\Fields\DateField('DATE'))
50 ->configureFormat(parent::FORMAT_SHORT)
51 ->configureColumnName($valueEntity->getField('VALUE')->getColumnName())
52 );
53 }
54
55 public static function ConvertToDB($arProperty, $value)
56 {
57 $dateTimeValue = (string)($value['VALUE'] ?? '');
58 if ($dateTimeValue !== '')
59 {
60 if (!static::checkInternalFormatValue($dateTimeValue))
61 {
62 $value['VALUE'] = CDatabase::FormatDate(
63 $dateTimeValue,
64 CLang::GetDateFormat('SHORT'),
65 self::INTERNAL_FORMAT
66 );
67 }
68 else
69 {
70 $value['VALUE'] = $dateTimeValue;
71 }
72 }
73
74 return $value;
75 }
76
77 public static function ConvertFromDB($arProperty, $value, $format = '')
78 {
79 $dateTimeValue = (string)($value['VALUE'] ?? '');
80 if ($dateTimeValue !== '')
81 {
82 $value['VALUE'] = CDatabase::FormatDate(
83 $dateTimeValue,
84 self::INTERNAL_FORMAT,
85 CLang::GetDateFormat('SHORT')
86 );
87 }
88
89 return $value;
90 }
91
92 public static function GetPublicEditHTML($arProperty, $value, $strHTMLControlName)
93 {
95 global $APPLICATION;
96
97 ob_start();
98 $APPLICATION->IncludeComponent(
99 'bitrix:iblock.property.field.public.edit',
100 'date',
101 [
102 'NAME' => $strHTMLControlName['VALUE'],
103 'VALUE' => static::prepareMultiValue($value),
104 'PROPERTY' => $arProperty,
105 'SHOW_TIME' => 'N',
106 ],
107 null,
108 [
109 'HIDE_ICONS' => 'Y',
110 ]
111 );
112 $result = ob_get_contents();
113 ob_end_clean();
114
115 return $result;
116 }
117
118 public static function GetPublicEditHTMLMulty($arProperty, $value, $strHTMLControlName): string
119 {
121 global $APPLICATION;
122
123 ob_start();
124 $APPLICATION->IncludeComponent(
125 'bitrix:iblock.property.field.public.edit',
126 'date',
127 [
128 'NAME' => $strHTMLControlName['VALUE'],
129 'VALUE' => static::prepareMultiValue($value),
130 'PROPERTY' => $arProperty,
131 'SHOW_TIME' => 'N',
132 ],
133 null,
134 [
135 'HIDE_ICONS' => 'Y',
136 ]
137 );
138 $result = ob_get_contents();
139 ob_end_clean();
140
141 return $result;
142
143 }
144
145 public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
146 {
147 return static::getPropertyFormField($arProperty, $value, $strHTMLControlName, false);
148 }
149
156 public static function GetUIFilterProperty($property, $control, &$fields)
157 {
158 parent::GetUIFilterProperty($property, $control, $fields);
159 unset($fields['time'], $fields['data']);
160 }
161
168 public static function GetUIEntityEditorProperty($settings, $value)
169 {
170 $culture = Context::getCurrent()->getCulture();
171
172 $dateTimeResult = parent::GetUIEntityEditorProperty($settings, $value);
173 $dateTimeResult['data'] = [
174 'enableTime' => false,
175 'dateViewFormat' => $culture->getLongDateFormat(),
176 ];
177
178 return $dateTimeResult;
179 }
180
181 protected static function checkInternalFormatValue(string $value): bool
182 {
183 if ($value === '')
184 {
185 return false;
186 }
187
188 $correctValue = date_parse_from_format(parent::FORMAT_SHORT, $value);
189
190 return ($correctValue['warning_count'] === 0 && $correctValue['error_count'] === 0);
191 }
192}
global $APPLICATION
Определения include.php:80
const TYPE_STRING
Определения propertytable.php:65
const USER_TYPE_DATE
Определения propertytable.php:75
Определения prop_date.php:8
static GetUIFilterProperty($property, $control, &$fields)
Определения prop_date.php:156
static GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
Определения prop_date.php:145
static GetUserTypeDescription()
Определения prop_date.php:14
static GetUIEntityEditorProperty($settings, $value)
Определения prop_date.php:168
static GetORMFields($valueEntity, $property)
Определения prop_date.php:46
static checkInternalFormatValue(string $value)
Определения prop_date.php:181
const USER_TYPE
Определения prop_date.php:10
static ConvertToDB($arProperty, $value)
Определения prop_date.php:55
static ConvertFromDB($arProperty, $value, $format='')
Определения prop_date.php:77
$result
Определения get_property_values.php:14
$control
Определения iblock_catalog_edit.php:61
$culture
Определения include.php:61
Определения culture.php:9
$settings
Определения product_settings.php:43
$fields
Определения yandex_run.php:501