1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
comp_formatprops.php
См. документацию.
1<?php
2
7
9{
10 private static ?bool $b24Installed = null;
11
12 private static array $userTypeCache = [];
13
14 private static array $nameCache = [
15 PropertyTable::TYPE_ELEMENT => [],
16 PropertyTable::TYPE_SECTION => [],
17 ];
18
19 private const USER_TYPE = 'UserType';
20
21 public static function GetDisplayValue($arItem, $arProperty, $event1 = '')
22 {
23 if (self::$b24Installed === null)
24 {
25 self::$b24Installed = ModuleManager::isModuleInstalled('bitrix24');
26 }
27
28 $arProperty['RAW_PROPERTY_TYPE'] = $arProperty['PROPERTY_TYPE'];
30 $arUserTypeFormat = false;
31 if (!empty($arProperty['USER_TYPE']))
32 {
33 $userTypeId = $arProperty['USER_TYPE'];
34 if (!isset(self::$userTypeCache[$userTypeId]))
35 {
36 self::$userTypeCache[$userTypeId] = false;
37 $arUserType = CIBlockProperty::GetUserType($userTypeId);
38 if (isset($arUserType['GetPublicViewHTML']))
39 {
40 self::$userTypeCache[$userTypeId] = $arUserType['GetPublicViewHTML'];
41 }
42 unset($arUserType);
43 }
44 $arUserTypeFormat = self::$userTypeCache[$userTypeId];
45 }
46
48 {
49 $arProperty['PROPERTY_TYPE'] = self::USER_TYPE;
50 if ($arProperty['MULTIPLE'] === 'N' || !is_array($arProperty['~VALUE']))
51 {
52 $arValues = [$arProperty['~VALUE']];
53 }
54 else
55 {
56 $arValues = $arProperty['~VALUE'];
57 }
58 }
59 else
60 {
61 if (is_array($arProperty['VALUE']))
62 {
63 $arValues = $arProperty['VALUE'];
64 }
65 else
66 {
67 $arValues = [$arProperty['VALUE']];
68 }
69 }
70 $arDisplayValue = [];
71
72 switch ($arProperty['PROPERTY_TYPE'])
73 {
74 case self::USER_TYPE:
75 foreach ($arValues as $val)
76 {
77 $arDisplayValue[] = (string)call_user_func_array(
79 [
80 $arProperty,
81 ['VALUE' => $val],
82 [],
83 ]
84 );
85 }
86 break;
87 case PropertyTable::TYPE_ELEMENT:
88 $arLinkElements = [];
89 foreach ($arValues as $val)
90 {
91 $val = (int)$val;
92 if ($val > 0)
93 {
94 if (!isset(self::$nameCache[PropertyTable::TYPE_ELEMENT][$val]))
95 {
96 //USED TO GET "LINKED" ELEMENTS
97 $rsLink = CIBlockElement::GetList(
98 [],
99 [
100 'ID' => $val,
101 'ACTIVE' => 'Y',
102 'ACTIVE_DATE' => 'Y',
103 'CHECK_PERMISSIONS' => 'Y',
104 'MIN_PERMISSION' => CIBlockRights::PUBLIC_READ,
105 ],
106 false,
107 false,
108 [
109 'ID',
110 'IBLOCK_ID',
111 'NAME',
112 'DETAIL_PAGE_URL',
113 'PREVIEW_PICTURE',
114 'DETAIL_PICTURE',
115 'SORT',
116 ]
117 );
118 self::$nameCache[PropertyTable::TYPE_ELEMENT][$val] = $rsLink->GetNext();
119 unset($rsLink);
120 }
121 if (is_array(self::$nameCache[PropertyTable::TYPE_ELEMENT][$val]))
122 {
123 $row = self::$nameCache[PropertyTable::TYPE_ELEMENT][$val];
124 if (self::$b24Installed)
125 {
126 $arDisplayValue[] = $row['NAME'];
127 }
128 else
129 {
130 $arDisplayValue[] = '<a href="' . $row['DETAIL_PAGE_URL'] . '">' . $row['NAME'] . '</a>';
131 }
132 $arLinkElements[$val] = $row;
133 unset($row);
134 }
135 }
136 }
137 $arProperty['LINK_ELEMENT_VALUE'] = (!empty($arLinkElements) ? $arLinkElements : false);
138 unset($arLinkElements);
139 break;
140 case PropertyTable::TYPE_SECTION:
141 $arLinkSections = [];
142 foreach ($arValues as $val)
143 {
144 $val = (int)$val;
145 if ($val > 0)
146 {
147 if (!isset(self::$nameCache[PropertyTable::TYPE_SECTION][$val]))
148 {
149 //USED TO GET SECTIONS NAMES
150 $rsSection = CIBlockSection::GetList(
151 [],
152 [
153 'ID' => $val,
154 'CHECK_PERMISSIONS' => 'Y',
155 'MIN_PERMISSION' => CIBlockRights::PUBLIC_READ,
156 ],
157 false,
158 [
159 'ID',
160 'IBLOCK_ID',
161 'NAME',
162 'SECTION_PAGE_URL',
163 'PICTURE',
164 'DETAIL_PICTURE',
165 'SORT',
166 ]
167 );
168 self::$nameCache[PropertyTable::TYPE_SECTION][$val] = $rsSection->GetNext();
169 unset($rsSection);
170 }
171 if (is_array(self::$nameCache[PropertyTable::TYPE_SECTION][$val]))
172 {
173 $row = self::$nameCache[PropertyTable::TYPE_SECTION][$val];
174 if (self::$b24Installed)
175 {
176 $arDisplayValue[] = $row['NAME'];
177 }
178 else
179 {
180 $arDisplayValue[] = '<a href="' . $row['SECTION_PAGE_URL'] . '">' . $row['NAME'] . '</a>';
181 }
182 $arLinkSections[$val] = self::$nameCache[PropertyTable::TYPE_SECTION][$val];
183 }
184 }
185 }
186 $arProperty['LINK_SECTION_VALUE'] = (!empty($arLinkSections) ? $arLinkSections : false);
187 unset($arLinkSections);
188 break;
189 case PropertyTable::TYPE_LIST:
190 $isCheckBox = Tools::isCheckboxProperty($arProperty);
191 foreach ($arValues as $val)
192 {
193 $val = (string)$val;
194 if ($isCheckBox)
195 {
196 if ($val === Tools::CHECKBOX_VALUE_YES)
197 {
198 $arDisplayValue[] = Loc::getMessage('IBLOCK_FORMATPROPS_PROPERTY_YES');
199 }
200 else
201 {
202 $arDisplayValue[] = Loc::getMessage('IBLOCK_FORMATPROPS_PROPERTY_NO');
203 }
204 }
205 else
206 {
207 if ($val !== '')
208 {
209 $arDisplayValue[] = $val;
210 }
211 }
212 }
213 unset($isCheckBox);
214 break;
215 case PropertyTable::TYPE_FILE:
216 $arFiles = [];
217 foreach ($arValues as $val)
218 {
219 if ($arFile = CFile::GetFileArray($val))
220 {
221 $arFiles[] = $arFile;
222 $arDisplayValue[] =
223 '<a href="' . htmlspecialcharsbx($arFile['SRC']) . '">'
224 . Loc::getMessage('IBLOCK_DOWNLOAD')
225 . '</a>'
226 ;
227 }
228 }
229 $fileCount = count($arFiles);
230 if ($fileCount == 1)
231 {
232 $arProperty['FILE_VALUE'] = $arFiles[0];
233 }
234 elseif ($fileCount > 1)
235 {
236 $arProperty['FILE_VALUE'] = $arFiles;
237 }
238 else
239 {
240 $arProperty['FILE_VALUE'] = false;
241 }
242 unset($fileCount, $arFiles);
243 break;
244 default:
245 foreach ($arValues as $val)
246 {
247 $trimmed = trim((string)$val);
248 if (strpos($trimmed, 'http') === 0)
249 {
250 $arDisplayValue[] = '<a href="' . htmlspecialcharsbx($trimmed) . '">' . $trimmed . '</a>';
251 }
252 elseif (strpos($trimmed, 'www') === 0)
253 {
254 $arDisplayValue[] = '<a href="' . htmlspecialcharsbx('https://' . $trimmed) . '">' . $trimmed . '</a>';
255 }
256 else
257 {
258 $arDisplayValue[] = $val;
259 }
260 }
261 break;
262 }
263
264 $displayCount = count($arDisplayValue);
265 if ($displayCount == 1)
266 {
267 $arProperty['DISPLAY_VALUE'] = $arDisplayValue[0];
268 }
269 elseif ($displayCount > 1)
270 {
271 $arProperty['DISPLAY_VALUE'] = $arDisplayValue;
272 }
273 else
274 {
275 $arProperty['DISPLAY_VALUE'] = false;
276 }
277
278 $arProperty['PROPERTY_TYPE'] = $arProperty['RAW_PROPERTY_TYPE'];
279 unset($arProperty['RAW_PROPERTY_TYPE']);
280
281 return $arProperty;
282 }
283
289 public static function DateFormat($format, $timestamp)
290 {
291 global $DB;
292
293 switch ($format)
294 {
295 case 'SHORT':
296 return FormatDate($DB->DateFormatToPHP(FORMAT_DATE), $timestamp);
297 case 'FULL':
298 return FormatDate($DB->DateFormatToPHP(FORMAT_DATETIME), $timestamp);
299 default:
300 return FormatDate($format, $timestamp);
301 }
302 }
303
304 public static function clearCache(): void
305 {
306 self::$userTypeCache = [];
307 self::$nameCache = [
308 PropertyTable::TYPE_ELEMENT => [],
309 PropertyTable::TYPE_SECTION => [],
310 ];
311 }
312}
static DateFormat($format, $timestamp)
Определения comp_formatprops.php:289
static clearCache()
Определения comp_formatprops.php:304
$arValues
Определения component_props.php:25
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $DB
Определения cron_frame.php:29
const FORMAT_DATETIME
Определения include.php:64
const FORMAT_DATE
Определения include.php:63
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
Определения tools.php:871
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$arFiles
Определения options.php:60
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
if(empty($arRunErrors)) $arUserTypeFormat
Определения yandex_run.php:788