1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
prop_datetime.php
См. документацию.
1<?php
2
8
10{
13
14 public const FORMAT_FULL = 'Y-m-d H:i:s';
15 public const FORMAT_SHORT = 'Y-m-d';
16
17 public static function GetUserTypeDescription()
18 {
19 return [
20 'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_STRING,
22 'DESCRIPTION' => Loc::getMessage('IBLOCK_PROP_DATETIME_DESC'),
23 //optional handlers
24 'GetPublicViewHTML' => [__CLASS__, 'GetPublicViewHTML'],
25 'GetPublicEditHTML' => [__CLASS__, 'GetPublicEditHTML'],
26 'GetPublicEditHTMLMulty' => [__CLASS__, 'GetPublicEditHTMLMulty'],
27 'GetAdminListViewHTML' => [__CLASS__, 'GetAdminListViewHTML'],
28 'GetPropertyFieldHtml' => [__CLASS__, 'GetPropertyFieldHtml'],
29 'CheckFields' => [__CLASS__, 'CheckFields'],
30 'ConvertToDB' => [__CLASS__, 'ConvertToDB'],
31 'ConvertFromDB' => [__CLASS__, 'ConvertFromDB'],
32 'GetSettingsHTML' => [__CLASS__, 'GetSettingsHTML'],
33 'GetAdminFilterHTML' => [__CLASS__, 'GetAdminFilterHTML'],
34 'GetPublicFilterHTML' => [__CLASS__, 'GetPublicFilterHTML'],
35 'AddFilterFields' => [__CLASS__, 'AddFilterFields'],
36 'GetUIFilterProperty' => [__CLASS__, 'GetUIFilterProperty'],
37 'GetUIEntityEditorProperty' => [__CLASS__, 'GetUIEntityEditorProperty'],
38 ];
39 }
40
41 public static function AddFilterFields($arProperty, $strHTMLControlName, &$arFilter, &$filtered)
42 {
43 $filtered = false;
44
45 $from = '';
46 $from_name = $strHTMLControlName['VALUE'] . '_from';
47 if (isset($strHTMLControlName['FILTER_ID']))
48 {
49 $filterOption = new Filter\Options($strHTMLControlName['FILTER_ID']);
50 $filterData = $filterOption->getFilter();
51 $from = !empty($filterData[$from_name]) ? $filterData[$from_name] : '';
52 }
53 elseif (isset($_REQUEST[$from_name]))
54 {
55 $from = $_REQUEST[$from_name];
56 }
57 elseif (
58 isset($strHTMLControlName['GRID_ID'])
59 && isset($_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$from_name])
60 )
61 {
62 $from = $_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$from_name];
63 }
64
65 if ($from)
66 {
67 $filterKey = '>=PROPERTY_' . $arProperty['ID'];
68 if (CheckDateTime($from))
69 {
70 $from = static::ConvertToDB(
71 $arProperty,
72 ['VALUE' => $from]
73 );
74 $arFilter[$filterKey] = $from['VALUE'];
75 }
76 else
77 {
78 $arFilter[$filterKey] = $from;
79 }
80 $filtered = true;
81 }
82
83 $to = '';
84 $to_name = $strHTMLControlName['VALUE'] . '_to';
85 if (isset($strHTMLControlName['FILTER_ID']))
86 {
87 $filterOption = new Filter\Options($strHTMLControlName['FILTER_ID']);
88 $filterData = $filterOption->getFilter();
89 $to = !empty($filterData[$to_name]) ? $filterData[$to_name] : '';
90 if ($to)
91 {
92 $dateFormat = Date::convertFormatToPhp(CSite::getDateFormat());
93 $dateParse = date_parse_from_format($dateFormat, $to);
94 if (!mb_strlen($dateParse['hour']) && !mb_strlen($dateParse['minute']) && !mb_strlen($dateParse['second']))
95 {
96 $timeFormat = Date::convertFormatToPhp(CSite::getTimeFormat());
97 $to .= ' ' . date($timeFormat, mktime(23, 59, 59, 0, 0, 0));
98 }
99 }
100 }
101 elseif (isset($_REQUEST[$to_name]))
102 {
103 $to = $_REQUEST[$to_name];
104 }
105 elseif (
106 isset($strHTMLControlName['GRID_ID'])
107 && isset($_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$to_name])
108 )
109 {
110 $to = $_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$to_name];
111 }
112
113 if ($to)
114 {
115 $filterKey = '<=PROPERTY_'.$arProperty['ID'];
116 if (CheckDateTime($to))
117 {
118 $to = static::ConvertToDB(
119 $arProperty,
120 ['VALUE' => $to]
121 );
122 $arFilter[$filterKey] = $to['VALUE'];
123 }
124 else
125 {
126 $arFilter[$filterKey] = $to;
127 }
128 $filtered = true;
129 }
130 }
131
132 public static function GetAdminFilterHTML($arProperty, $strHTMLControlName)
133 {
134 $from_name = $strHTMLControlName["VALUE"] . '_from';
135 $to_name = $strHTMLControlName["VALUE"] . '_to';
136
137 $lAdmin = new CAdminList($strHTMLControlName["TABLE_ID"]);
138 $lAdmin->InitFilter(array(
139 $from_name,
140 $to_name,
141 ));
142
143 $from = $GLOBALS[$from_name] ?? "";
144 $to = $GLOBALS[$to_name] ?? "";
145
146 return CAdminCalendar::CalendarPeriod($from_name, $to_name, $from, $to);
147 }
148
149 public static function GetPublicFilterHTML($arProperty, $strHTMLControlName)
150 {
152 global $APPLICATION;
153
154 $from_name = $strHTMLControlName['VALUE'] . '_from';
155 $to_name = $strHTMLControlName['VALUE'] . '_to';
156
157 if (isset($_REQUEST[$from_name]))
158 {
159 $from = $_REQUEST[$from_name];
160 }
161 elseif (
162 isset($strHTMLControlName['GRID_ID'])
163 && isset($_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$from_name])
164 )
165 {
166 $from = $_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$from_name];
167 }
168 else
169 {
170 $from = '';
171 }
172
173 if (isset($_REQUEST[$to_name]))
174 {
175 $to = $_REQUEST[$to_name];
176 }
177 elseif (
178 isset($strHTMLControlName['GRID_ID'])
179 && isset($_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$to_name])
180 )
181 {
182 $to = $_SESSION['main.interface.grid'][$strHTMLControlName['GRID_ID']]['filter'][$to_name];
183 }
184 else
185 {
186 $to = '';
187 }
188
189 ob_start();
190
191 $APPLICATION->IncludeComponent(
192 'bitrix:main.calendar',
193 '',
194 array(
195 'FORM_NAME' => $strHTMLControlName['FORM_NAME'] ?? '',
196 'SHOW_INPUT' => 'Y',
197 'INPUT_NAME' => $from_name,
198 'INPUT_VALUE' => $from,
199 'INPUT_NAME_FINISH' => $to_name,
200 'INPUT_VALUE_FINISH' => $to,
201 'INPUT_ADDITIONAL_ATTR' => 'size="10"',
202 ),
203 null,
204 array('HIDE_ICONS' => 'Y')
205 );
206
207 $s = ob_get_contents();
208 ob_end_clean();
209
210 return $s;
211 }
212
213 public static function GetPublicViewHTML($arProperty, $value, $strHTMLControlName)
214 {
215 if ($value["VALUE"] <> '')
216 {
217 if (!CheckDateTime($value["VALUE"]))
218 {
219 $value = static::ConvertFromDB($arProperty, $value, $strHTMLControlName["DATETIME_FORMAT"] ?? '');
220 }
221
222 if (isset($strHTMLControlName["MODE"]))
223 {
224 if ($strHTMLControlName["MODE"] == "CSV_EXPORT")
225 return $value["VALUE"];
226 elseif ($strHTMLControlName["MODE"] == "SIMPLE_TEXT")
227 return $value["VALUE"];
228 elseif ($strHTMLControlName["MODE"] == "ELEMENT_TEMPLATE")
229 return $value["VALUE"];
230 }
231 return str_replace(" ", "&nbsp;", htmlspecialcharsEx($value["VALUE"]));
232 }
233
234 return '';
235 }
236
237 public static function GetPublicEditHTML($arProperty, $value, $strHTMLControlName)
238 {
240 global $APPLICATION;
241
242 ob_start();
243 $APPLICATION->IncludeComponent(
244 'bitrix:iblock.property.field.public.edit',
245 'date',
246 [
247 'NAME' => $strHTMLControlName['VALUE'],
248 'VALUE' => static::prepareMultiValue($value),
249 'PROPERTY' => $arProperty,
250 'SHOW_TIME' => 'Y',
251 ],
252 null,
253 [
254 'HIDE_ICONS' => 'Y',
255 ]
256 );
257 $result = ob_get_contents();
258 ob_end_clean();
259
260 return $result;
261 }
262
263 public static function GetPublicEditHTMLMulty($arProperty, $value, $strHTMLControlName): string
264 {
266 global $APPLICATION;
267
268 ob_start();
269 $APPLICATION->IncludeComponent(
270 'bitrix:iblock.property.field.public.edit',
271 'date',
272 [
273 'NAME' => $strHTMLControlName['VALUE'],
274 'VALUE' => static::prepareMultiValue($value),
275 'PROPERTY' => $arProperty,
276 'SHOW_TIME' => 'Y',
277 ],
278 null,
279 [
280 'HIDE_ICONS' => 'Y',
281 ]
282 );
283 $result = ob_get_contents();
284 ob_end_clean();
285
286 return $result;
287 }
288
289 public static function GetAdminListViewHTML($arProperty, $value, $strHTMLControlName)
290 {
291 if($value["VALUE"] <> '')
292 {
293 if(!CheckDateTime($value["VALUE"]))
294 $value = static::ConvertFromDB($arProperty, $value);
295 return str_replace(" ", "&nbsp;", htmlspecialcharsex($value["VALUE"]));
296 }
297 else
298 return '&nbsp;';
299 }
300
301 //PARAMETERS:
302 //$arProperty - b_iblock_property.*
303 //$value - array("VALUE","DESCRIPTION") -- here comes HTML form value
304 //strHTMLControlName - array("VALUE","DESCRIPTION")
305 //return:
306 //safe html
307 public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
308 {
309 return static::getPropertyFormField($arProperty, $value, $strHTMLControlName, true);
310 }
311
312 protected static function getPropertyFormField(
313 $property,
314 $value,
315 $controlDescription,
316 bool $useTime
317 ): string
318 {
319 if (!is_array($property))
320 {
321 $property = [];
322 }
323 $property['WITH_DESCRIPTION'] = ($property['WITH_DESCRIPTION'] ?? 'N') === 'Y' ? 'Y' : 'N';
324
325 if (!is_array($value))
326 {
327 $value = [];
328 }
329 $value['VALUE'] ??= '';
330 $value['DESCRIPTION'] ??= '';
331 if (!is_string($value['DESCRIPTION']))
332 {
333 $value['DESCRIPTION'] = '';
334 }
335
336 if (!is_array($controlDescription))
337 {
338 $controlDescription = [];
339 }
340 $controlDescription['VALUE'] ??= '';
341 $controlDescription['DESCRIPTION'] ??= '';
342 if (!is_string($controlDescription['DESCRIPTION']))
343 {
344 $controlDescription['DESCRIPTION'] = '';
345 }
346 $controlDescription['DESCRIPTION'] = trim($controlDescription['DESCRIPTION']);
347
348 $result = CAdminCalendar::CalendarDate($controlDescription['VALUE'], $value['VALUE'], 20, $useTime);
349 if (
350 $property['WITH_DESCRIPTION'] === 'Y'
351 && $controlDescription['DESCRIPTION'] !== ''
352 )
353 {
354 $result .= '&nbsp;<input type="text" size="20" name="' . $controlDescription['DESCRIPTION'].'"'
355 .' value="' . htmlspecialcharsbx($value['DESCRIPTION'] ?? '') . '">'
356 ;
357 }
358
359 return $result;
360 }
361
362 //PARAMETERS:
363 //$arProperty - b_iblock_property.*
364 //$value - array("VALUE",["DESCRIPTION"]) -- here comes HTML form value
365 //return:
366 //array of error messages
367 public static function CheckFields($arProperty, $value)
368 {
369 $arResult = [];
370 $dateTimeValue = (string)($value["VALUE"] ?? '');
371 if ($dateTimeValue !== '')
372 {
373 if (
374 !CheckDateTime($dateTimeValue)
375 && !static::checkInternalFormatValue($dateTimeValue)
376 )
377 {
378 $arResult[] = Loc::getMessage(
379 'IBLOCK_PROP_DATETIME_ERROR_NEW',
380 [
381 '#FIELD_NAME#' => $arProperty['NAME'],
382 ]
383 );
384 }
385 }
386
387 return $arResult;
388 }
389
390 //PARAMETERS:
391 //$arProperty - b_iblock_property.*
392 //$value - array("VALUE",["DESCRIPTION"]) -- here comes HTML form value
393 //return:
394 //DB form of the value
395 public static function ConvertToDB($arProperty, $value)
396 {
397 $dateTimeValue = (string)($value['VALUE'] ?? '');
398 if ($dateTimeValue !== '')
399 {
400 if (!static::checkInternalFormatValue($dateTimeValue))
401 {
402 try
403 {
405
406 $value['VALUE'] = $time->format(static::FORMAT_FULL);
407 }
408 catch (Bitrix\Main\ObjectException $e)
409 {
410 }
411 }
412 else
413 {
414 $value['VALUE'] = $dateTimeValue;
415 }
416 }
417
418 return $value;
419 }
420
421 public static function ConvertFromDB($arProperty, $value, $format = '')
422 {
423 $dateTimeValue = (string)($value['VALUE'] ?? '');
424 if ($dateTimeValue !== '')
425 {
426 try
427 {
428 $time = new Bitrix\Main\Type\DateTime($dateTimeValue, self::FORMAT_FULL);
429 $time->toUserTime();
430
431 if ($format === 'SHORT')
432 $phpFormat = $time->convertFormatToPhp(FORMAT_DATE);
433 elseif ($format === 'FULL')
434 $phpFormat = $time->convertFormatToPhp(FORMAT_DATETIME);
435 elseif ($format)
436 $phpFormat = $time->convertFormatToPhp($format);
437 else
438 $phpFormat = $time->getFormat();
439
440 $value["VALUE"] = $time->format($phpFormat);
441 $value["VALUE"] = str_replace(" 00:00:00", "", $value["VALUE"]);
442 }
443 catch(Bitrix\Main\ObjectException $e)
444 {
445 }
446 }
447
448 return $value;
449 }
450
451 public static function GetSettingsHTML($arProperty, $strHTMLControlName, &$arPropertyFields)
452 {
453 $arPropertyFields = [
454 'HIDE' => [
455 'ROW_COUNT',
456 'COL_COUNT',
457 ],
458 ];
459
460 return '';
461 }
462
469 public static function GetUIFilterProperty($property, $control, &$fields)
470 {
471 $fields['type'] = 'date';
472 $fields['time'] = true;
473 $fields['data'] = [
474 'time' => true,
475 ];
476 $fields['filterable'] = '';
477 $fields['operators'] = [
478 'default' => '=',
479 'exact' => '=',
480 'range' => '><',
481 'more' => '>',
482 'less' => '<',
483 ];
484 }
485
486 public static function GetUIEntityEditorProperty($settings, $value)
487 {
488 $culture = Context::getCurrent()->getCulture();
489
490 return [
491 'type' => ($settings['MULTIPLE'] === 'Y') ? 'multidatetime' : 'datetime',
492 'data' => [
493 'enableTime' => true,
494 'dateViewFormat' => $culture->getLongDateFormat() . ' ' . $culture->getShortTimeFormat(),
495 ]
496 ];
497 }
498
499 protected static function checkInternalFormatValue(string $value): bool
500 {
501 if ($value === '')
502 {
503 return false;
504 }
505
506 $correctValue = date_parse_from_format(self::FORMAT_FULL, $value);
507 if ($correctValue['warning_count'] === 0 && $correctValue['error_count'] === 0)
508 {
509 return true;
510 }
511
512 $correctValue = date_parse_from_format(self::FORMAT_SHORT, $value);
513
514 return ($correctValue['warning_count'] === 0 && $correctValue['error_count'] === 0);
515 }
516
517 protected static function prepareMultiValue(mixed $value): ?array
518 {
519 if (empty($value))
520 {
521 return null;
522 }
523 if (!is_array($value))
524 {
525 $value = [$value];
526 }
527 if (isset($value['VALUE']))
528 {
529 $rawValue = is_array($value['VALUE']) ? $value['VALUE'] : [$value['VALUE']];
530 }
531 else
532 {
533 $rawValue = [];
534 foreach ($value as $row)
535 {
536 if (!is_array($row))
537 {
538 $row = [
539 'VALUE' => $row,
540 ];
541 }
542 $rawValue[] = $row['VALUE'];
543 }
544 }
545
546 return array_filter($rawValue);
547 }
548}
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
const TYPE_STRING
Определения propertytable.php:65
const USER_TYPE_DATETIME
Определения propertytable.php:76
Определения date.php:9
static convertFormatToPhp($format)
Определения date.php:309
static createFromUserTime($timeString)
Определения datetime.php:180
static CalendarDate($sFieldName, $sValue="", $size="10", $bTime=false)
Определения admin_calendar.php:78
static CalendarPeriod($sFromName, $sToName, $sFromVal="", $sToVal="", $bSelectShow=false, $size=10, $bTime=false)
Определения admin_calendar.php:142
Определения admin_list.php:16
static GetUIFilterProperty($property, $control, &$fields)
Определения prop_datetime.php:469
static GetPublicViewHTML($arProperty, $value, $strHTMLControlName)
Определения prop_datetime.php:213
static CheckFields($arProperty, $value)
Определения prop_datetime.php:367
static GetSettingsHTML($arProperty, $strHTMLControlName, &$arPropertyFields)
Определения prop_datetime.php:451
static AddFilterFields($arProperty, $strHTMLControlName, &$arFilter, &$filtered)
Определения prop_datetime.php:41
static getPropertyFormField( $property, $value, $controlDescription, bool $useTime)
Определения prop_datetime.php:312
static GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
Определения prop_datetime.php:307
static GetUserTypeDescription()
Определения prop_datetime.php:17
static GetAdminListViewHTML($arProperty, $value, $strHTMLControlName)
Определения prop_datetime.php:289
const FORMAT_SHORT
Определения prop_datetime.php:15
static GetUIEntityEditorProperty($settings, $value)
Определения prop_datetime.php:486
static prepareMultiValue(mixed $value)
Определения prop_datetime.php:517
static checkInternalFormatValue(string $value)
Определения prop_datetime.php:499
const FORMAT_FULL
Определения prop_datetime.php:14
static GetAdminFilterHTML($arProperty, $strHTMLControlName)
Определения prop_datetime.php:132
const USER_TYPE
Определения prop_datetime.php:12
static ConvertToDB($arProperty, $value)
Определения prop_datetime.php:395
static ConvertFromDB($arProperty, $value, $format='')
Определения prop_datetime.php:421
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
$result
Определения get_property_values.php:14
$control
Определения iblock_catalog_edit.php:61
const FORMAT_DATETIME
Определения include.php:64
const FORMAT_DATE
Определения include.php:63
$culture
Определения include.php:61
htmlspecialcharsEx($str)
Определения tools.php:2685
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
CheckDateTime($datetime, $format=false)
Определения tools.php:398
Определения culture.php:9
Определения actions.php:3
$GLOBALS['____1690880296']
Определения license.php:1
$time
Определения payment.php:61
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$lAdmin
Определения update_log.php:25
$arFilter
Определения user_search.php:106
$fields
Определения yandex_run.php:501