20 private const STRICT_FIELD_FORMAT =
'/^\-?[0-9]+\.?[0-9]*\|[A-Z]{3}$/';
21 private const LIGHT_FIELD_FORMAT =
'/^\-?[0-9]+\.?[0-9]*(\|[A-Z]{3})?$/';
27 'BASE_TYPE' => CUserTypeManager::BASE_TYPE_STRING,
36 return 'varchar(200)';
39 public static function checkFields(array $userField, $value): array
42 $userField[
'EDIT_FORM_LABEL'] ?: $userField[
'FIELD_NAME']
47 if ($userField[
'MULTIPLE'] ===
'N')
49 if (!self::checkValueFormat($userField, $value))
52 'id' => $userField[
'FIELD_NAME'],
55 '#FIELD_NAME#' => $fieldName,
65 foreach ($value as $row)
69 || !self::checkValueFormat($userField, $row)
73 'id' => $userField[
'FIELD_NAME'],
76 '#FIELD_NAME#' => $fieldName,
86 if (!self::checkValueFormat($userField, $value))
89 'id' => $userField[
'FIELD_NAME'],
92 '#FIELD_NAME#' => $fieldName,
110 if ($value ===
'' || $value ===
null)
115 if (!self::checkValueFormat($userField, $value))
120 [$value, $currency] = static::unFormatFromDb($value);
126 if (self::isStrictFormat($userField))
130 $currency = CurrencyManager::getBaseCurrency();
133 return static::formatToDB($value, $currency);
145 [$value, $currency] = static::unFormatFromDb($userField[
'SETTINGS'][
'DEFAULT_VALUE'] ??
null);
150 $currency = CurrencyManager::getBaseCurrency();
152 $value = static::formatToDB($value, $currency);
156 'DEFAULT_VALUE' => $value,
165 public static function formatToDb(
string $value, ?
string $currency): string
172 $value = (string)((
float)$value);
173 $currency = trim((
string)$currency);
175 return $value . static::DB_SEPARATOR . $currency;
184 if ($value ===
null || $value ===
'')
192 $result = explode(static::DB_SEPARATOR, $value);
193 if (count($result) === 1)
201 private static function checkValueFormat(array $userField, $value): bool
203 if ($value ===
'' || $value ===
null)
208 $isStrictFormat = self::isStrictFormat($userField);
210 if (!$isStrictFormat)
217 $value = (string)$value;
221 if (!is_string($value))
226 $format = $isStrictFormat
227 ? self::STRICT_FIELD_FORMAT
228 : self::LIGHT_FIELD_FORMAT
231 if (!preg_match($format, $value, $prepared))
239 private static function isStrictFormat(array $userField): bool
241 return ($userField[
'SETTINGS'][
'STRICT_FORMAT'] ??
'N') ===
'Y';
static loadLanguageFile($file, $language=null, $normalize=true)
static getMessage($code, $replace=null, $language=null)
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)