1C-Bitrix 25.700.0
editor.php
См. документацию.
1<?php
2
4
6
7class Editor
8{
9 protected const VALUE_MASK = '/^([+-]?)([0-9]*)(\.[0-9]*)?$/';
10
11 protected static array $listCurrencyCache;
12
18 public static function getListCurrency(): array
19 {
20 if (!isset(static::$listCurrencyCache))
21 {
22 static::$listCurrencyCache = [];
23
24 $separators = \CCurrencyLang::GetSeparators();
26
27 $defaultFormat = \CCurrencyLang::GetDefaultValues();
28 $defaultFormat['SEPARATOR'] = $separators[$defaultFormat['THOUSANDS_VARIANT']];
29
31 'select' => [
32 'CURRENCY',
33 'NAME' => 'CURRENCY',
34 'BASE',
35 'SORT',
36 ],
37 'order' => [
38 'SORT' => 'ASC',
39 'CURRENCY' => 'ASC',
40 ],
41 'cache' => [
42 'ttl' => 86400,
43 ],
44 ]);
45 while ($row = $iterator->fetch())
46 {
47 unset($row['SORT']);
48 static::$listCurrencyCache[$row['CURRENCY']] = array_merge($row, $defaultFormat);
49 }
50 unset($row, $iterator);
51
52 if (!empty(static::$listCurrencyCache))
53 {
55 'select' => [
56 'CURRENCY',
57 'FULL_NAME',
58 'FORMAT_STRING',
59 'DEC_POINT',
60 'THOUSANDS_VARIANT',
61 'DECIMALS',
62 'THOUSANDS_SEP',
63 'HIDE_ZERO',
64 ],
65 'filter' => [
66 '@CURRENCY' => array_keys(static::$listCurrencyCache),
67 '=LID' => LANGUAGE_ID,
68 ],
69 'cache' => [
70 'ttl' => 86400,
71 ],
72 ]);
73 while ($row = $iterator->fetch())
74 {
75 $currencyId = $row['CURRENCY'];
76 $row['FULL_NAME'] = (string)$row['FULL_NAME'];
77 if ($row['FULL_NAME'] !== '')
78 {
79 static::$listCurrencyCache[$currencyId]['NAME'] = $row['FULL_NAME'];
80 }
81
82 unset($row['FULL_NAME'], $row['CURRENCY']);
83 static::$listCurrencyCache[$currencyId] = array_merge(
84 static::$listCurrencyCache[$currencyId],
85 $row
86 );
87
88 if ($row['THOUSANDS_VARIANT'] !== null && isset($separators[$row['THOUSANDS_VARIANT']]))
89 {
90 static::$listCurrencyCache[$currencyId]['SEPARATOR'] = $separators[$row['THOUSANDS_VARIANT']];
91 }
92 else
93 {
94 static::$listCurrencyCache[$currencyId]['SEPARATOR'] = $row['THOUSANDS_SEP'];
95 }
96 }
97 }
98 unset($row, $iterator);
99 }
100
101 return static::$listCurrencyCache;
102 }
103
110 public static function parseValue(mixed $value): ?array
111 {
112 if (!is_string($value))
113 {
114 return null;
115 }
116
117 $parsedValue = [];
118 if (preg_match(self::VALUE_MASK, $value, $parsedValue))
119 {
120 $parsedValue[3] ??= '';
121 return $parsedValue;
122 }
123
124 return null;
125 }
126
133 public static function prepareValue($value): string|int|float
134 {
135 if (is_int($value) || is_float($value))
136 {
137 return $value;
138 }
139
140 if (!is_string($value))
141 {
142 return '';
143 }
144 $value = trim($value);
145 if ($value === '')
146 {
147 return '';
148 }
149
150 $parsedValue = static::parseValue($value);
151 if ($parsedValue === null)
152 {
153 return (float)$value;
154 }
155
156 $result =
157 ($parsedValue[1] === '-' ? '-' : '')
158 . ($parsedValue[2] === '' ? '0' : $parsedValue[2])
159 ;
160
161 if ($parsedValue[3] !== '' && $parsedValue[3] !== '.')
162 {
163 $fraction = rtrim($parsedValue[3], '0');
164 if ($fraction !== '.')
165 {
166 $result .= $fraction;
167 }
168 }
169
170 return $result;
171 }
172}
const VALUE_MASK
Определения editor.php:9
static parseValue(mixed $value)
Определения editor.php:110
static getListCurrency()
Определения editor.php:18
static prepareValue($value)
Определения editor.php:133
static array $listCurrencyCache
Определения editor.php:11
static getList(array $parameters=array())
Определения datamanager.php:431
</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
$iterator
Определения yandex_run.php:610