1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ValidateGetOpenEventList.php
См. документацию.
1<?php
2
4
9
11{
13 {
14 $request = $this->getAction()->getController()->getRequest();
15 $categoryId = $request->get('categoryId');
16 if ($categoryId && $categoryId < 0)
17 {
18 $this->addError(
19 new Error(
20 message: 'categoryId should be positive integer',
21 customData: ['field_name' => 'categoryId'],
22 )
23 );
24 }
25
26 $onlyCurrentUser = $request['onlyCurrentUser'] ?? null;
27 $this->validateBool($onlyCurrentUser, 'onlyCurrentUser');
28
29 $onlyWithComments = $request['onlyWithComments'] ?? null;
30 $this->validateBool($onlyWithComments, 'onlyWithComments');
31
32 $fromYear = $request['fromYear'] ?? null;
33 $this->validateYear($fromYear, 'fromYear');
34
35 $fromMonth = $request['fromMonth'] ?? null;
36 $this->validateMonth($fromMonth, 'fromMonth');
37
38 $toYear = $request['toYear'] ?? null;
39 $this->validateYear($toYear, 'toYear');
40
41 $toMonth = $request['toMonth'] ?? null;
42 $this->validateMonth($toMonth, 'toMonth');
43
44 return null;
45 }
46
47 private function validateBool($value, string $fieldName): void
48 {
49 if (
50 is_string($value)
51 && !in_array($value, ['true', 'false'], true)
52 )
53 {
54 $this->addFieldError(
55 sprintf('%s should be true|false', $fieldName),
56 $fieldName
57 );
58 }
59 }
60
61 private function validateYear($value, string $fieldName): void
62 {
63 if (
64 is_string($value)
65 && $value
66 && (int)$value < 2000
67 )
68 {
69 $this->addFieldError(sprintf('%s should be valid year', $fieldName), $fieldName);
70 }
71 }
72
73 private function validateMonth($value, string $fieldName): void
74 {
75 if (
76 is_string($value)
77 && $value
78 && ((int)$value < 1 || (int)$value > 12)
79 )
80 {
81 $this->addFieldError(sprintf('%s should be valid month', $fieldName), $fieldName);
82 }
83 }
84
85 private function addFieldError(string $message, string $fieldName): void
86 {
87 $this->addError(
88 new Error(
89 message: $message,
90 customData: ['field_name' => $fieldName],
91 )
92 );
93 }
94}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
addError(Error $error)
Определения base.php:80
Определения error.php:15
Определения event.php:5
$message
Определения payment.php:8
$event
Определения prolog_after.php:141