1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
doubletype.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\UserField\Types;
4
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Main\Text\HtmlFilter;
7use CUserTypeManager;
8
9Loc::loadMessages(__FILE__);
10
15class DoubleType extends BaseType
16{
17 public const
18 USER_TYPE_ID = 'double',
19 RENDER_COMPONENT = 'bitrix:main.field.double';
20
24 public static function getDescription(): array
25 {
26 return [
27 'DESCRIPTION' => GetMessage('USER_TYPE_DOUBLE_DESCRIPTION'),
28 'BASE_TYPE' => CUserTypeManager::BASE_TYPE_DOUBLE,
29 ];
30 }
31
35 public static function getDbColumnType(): string
36 {
38 $helper = $connection->getSqlHelper();
39 return $helper->getColumnTypeByField(new \Bitrix\Main\ORM\Fields\FloatField('x'));
40 }
41
46 public static function prepareSettings(array $userField): array
47 {
48 $prec = (int)($userField['SETTINGS']['PRECISION'] ?? 0);
49 $size = (int)($userField['SETTINGS']['SIZE'] ?? 0);
50 $min = (double)($userField['SETTINGS']['MIN_VALUE'] ?? 0);
51 $max = (double)($userField['SETTINGS']['MAX_VALUE'] ?? 0);
52 $defaultValue = is_numeric($userField['SETTINGS']['DEFAULT_VALUE'] ?? null)
53 ? (double)$userField['SETTINGS']['DEFAULT_VALUE']
54 : null
55 ;
56
57 return [
58 'PRECISION' => ($prec < 0 ? 0 : ($prec > 12 ? 12 : $prec)),
59 'SIZE' => ($size <= 1 ? 20 : ($size > 255 ? 225 : $size)),
60 'MIN_VALUE' => $min,
61 'MAX_VALUE' => $max,
62 'DEFAULT_VALUE' => $defaultValue,
63 ];
64 }
65
71 public static function getFilterData(?array $userField, array $additionalSettings): array
72 {
73 return [
74 'id' => $additionalSettings['ID'],
75 'name' => $additionalSettings['NAME'],
76 'type' => 'number',
77 'filterable' => ''
78 ];
79 }
80
86 public static function checkFields(array $userField, $value): array
87 {
88 $msg = [];
89
90 $value = str_replace([',', ' '], ['.', ''], $value);
91
92 $fieldName = HtmlFilter::encode(
93 $userField['EDIT_FORM_LABEL'] <> ''
94 ? $userField['EDIT_FORM_LABEL'] : $userField['FIELD_NAME']
95 );
96
97 if(
98 mb_strlen($value)
99 && $userField['SETTINGS']['MIN_VALUE'] != 0
100 && (double)$value < $userField['SETTINGS']['MIN_VALUE']
101 )
102 {
103 $msg[] = [
104 'id' => $userField['FIELD_NAME'],
105 'text' => Loc::getMessage(
106 'USER_TYPE_DOUBLE_MIN_VALUE_ERROR',
107 [
108 '#FIELD_NAME#' => $fieldName,
109 '#MIN_VALUE#' => $userField['SETTINGS']['MIN_VALUE']
110 ]
111 )
112 ];
113 }
114 if(
115 mb_strlen($value)
116 && $userField['SETTINGS']['MAX_VALUE'] != 0
117 && (double)$value > $userField['SETTINGS']['MAX_VALUE']
118 )
119 {
120 $msg[] = [
121 'id' => $userField['FIELD_NAME'],
122 'text' => Loc::getMessage(
123 'USER_TYPE_DOUBLE_MAX_VALUE_ERROR',
124 [
125 '#FIELD_NAME#' => $fieldName,
126 '#MAX_VALUE#' => $userField['SETTINGS']['MAX_VALUE']
127 ]
128 ),
129 ];
130 }
131 if(
132 $value != ''
133 && !preg_match('/^[-+]?\d*[.,]?\d+?$/', $value)
134 )
135 {
136 $msg[] = [
137 'id' => $userField['FIELD_NAME'],
138 'text' => Loc::getMessage('USER_TYPE_DOUBLE_TYPE_ERROR',
139 [
140 '#FIELD_NAME#' => $fieldName
141 ]
142 ),
143 ];
144 }
145 return $msg;
146 }
147
152 public static function onSearchIndex(array $userField): ?string
153 {
154 if(is_array($userField['VALUE']))
155 {
156 $result = implode('\r\n', $userField['VALUE']);
157 }
158 else
159 {
160 $result = $userField['VALUE'];
161 }
162 return $result;
163 }
164
170 public static function onBeforeSave(array $userField, $value)
171 {
172 $value = str_replace([',', ' '], ['.', ''], $value);
173 if($value <> '')
174 {
175 return (string) round((double)$value, $userField['SETTINGS']['PRECISION']);
176 }
177 return null;
178 }
179}
$connection
Определения actionsdefinitions.php:38
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
static getConnection($name="")
Определения application.php:638
static getFilterData(?array $userField, array $additionalSettings)
Определения doubletype.php:71
static onBeforeSave(array $userField, $value)
Определения doubletype.php:170
static onSearchIndex(array $userField)
Определения doubletype.php:152
static checkFields(array $userField, $value)
Определения doubletype.php:86
static prepareSettings(array $userField)
Определения doubletype.php:46
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$max
Определения template_copy.php:262