1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
prop_element_list.php
См. документацию.
1<?php
2
5
7{
10
11 public static function GetUserTypeDescription()
12 {
13 return [
14 'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_ELEMENT,
16 'DESCRIPTION' => Loc::getMessage('IBLOCK_PROP_ELIST_DESC'),
17 'GetPropertyFieldHtml' => [__CLASS__, 'GetPropertyFieldHtml'],
18 'GetPropertyFieldHtmlMulty' => [__CLASS__, 'GetPropertyFieldHtmlMulty'],
19 'GetPublicEditHTML' => [__CLASS__, 'GetPropertyFieldHtml'],
20 'GetPublicEditHTMLMulty' => [__CLASS__, 'GetPropertyFieldHtmlMulty'],
21 'GetPublicViewHTML' => [__CLASS__, 'GetPublicViewHTML'],
22 'GetUIFilterProperty' => [__CLASS__, 'GetUIFilterProperty'],
23 'GetAdminFilterHTML' => [__CLASS__, 'GetAdminFilterHTML'],
24 'PrepareSettings' => [__CLASS__, 'PrepareSettings'],
25 'GetSettingsHTML' => [__CLASS__, 'GetSettingsHTML'],
26 'GetExtendedValue' => [__CLASS__, 'GetExtendedValue'],
27 'GetUIEntityEditorProperty' => [__CLASS__, 'GetUIEntityEditorProperty'],
28 ];
29 }
30
31 public static function PrepareSettings($arProperty)
32 {
33 $size = (int)($arProperty['USER_TYPE_SETTINGS']['size'] ?? 0);
34 if ($size <= 0)
35 {
36 $size = 1;
37 }
38
39 $width = (int)($arProperty['USER_TYPE_SETTINGS']['width'] ?? 0);
40 if ($width <= 0)
41 {
42 $width = 0;
43 }
44
45 $group = ($arProperty['USER_TYPE_SETTINGS']['group'] ?? 'N');
46 $group = ($group === 'Y' ? 'Y' : 'N');
47
48 $multiple = ($arProperty['USER_TYPE_SETTINGS']['multiple'] ?? 'N');
49 $multiple = ($multiple === 'Y' ? 'Y' : 'N');
50
51 return [
52 'size' => $size,
53 'width' => $width,
54 'group' => $group,
55 'multiple' => $multiple,
56 ];
57 }
58
59 public static function GetSettingsHTML($arProperty, $strHTMLControlName, &$arPropertyFields)
60 {
62
63 $arPropertyFields = [
64 'HIDE' => [
65 'ROW_COUNT',
66 'COL_COUNT',
67 'MULTIPLE_CNT',
68 ],
69 ];
70
71 return '
72 <tr valign="top">
73 <td>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_SETTING_SIZE").':</td>
74 <td><input type="text" size="5" name="'.$strHTMLControlName["NAME"].'[size]" value="'.$settings["size"].'"></td>
75 </tr>
76 <tr valign="top">
77 <td>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_SETTING_WIDTH").':</td>
78 <td><input type="text" size="5" name="'.$strHTMLControlName["NAME"].'[width]" value="'.$settings["width"].'">px</td>
79 </tr>
80 <tr valign="top">
81 <td>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_SETTING_SECTION_GROUP").':</td>
82 <td><input type="checkbox" name="'.$strHTMLControlName["NAME"].'[group]" value="Y" '.($settings["group"]=="Y"? 'checked': '').'></td>
83 </tr>
84 <tr valign="top">
85 <td>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_SETTING_MULTIPLE").':</td>
86 <td><input type="checkbox" name="'.$strHTMLControlName["NAME"].'[multiple]" value="Y" '.($settings["multiple"]=="Y"? 'checked': '').'></td>
87 </tr>
88 ';
89 }
90
91 //PARAMETERS:
92 //$arProperty - b_iblock_property.*
93 //$value - array("VALUE","DESCRIPTION") -- here comes HTML form value
94 //strHTMLControlName - array("VALUE","DESCRIPTION")
95 //return:
96 //safe html
97 public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
98 {
100 if($settings["size"] > 1)
101 $size = ' size="'.$settings["size"].'"';
102 else
103 $size = '';
104
105 if($settings["width"] > 0)
106 $width = ' style="width:'.$settings["width"].'px"';
107 else
108 $width = '';
109
110 $bWasSelect = false;
111 $options = CIBlockPropertyElementList::GetOptionsHtml($arProperty, array($value["VALUE"]), $bWasSelect);
112
113 $html = '<select name="'.$strHTMLControlName["VALUE"].'"'.$size.$width.'>';
114 $arProperty['IS_REQUIRED'] ??= 'N';
115 if($arProperty['IS_REQUIRED'] !== 'Y')
116 {
117 $html .= '<option value=""'.(!$bWasSelect ? ' selected' : '').'>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_NO_VALUE").'</option>';
118 }
119 $html .= $options;
120 $html .= '</select>';
121
122 return $html;
123 }
124
125 public static function GetPropertyFieldHtmlMulty($arProperty, $value, $strHTMLControlName)
126 {
127 $max_n = 0;
128 $values = array();
129 if(is_array($value))
130 {
131 foreach($value as $property_value_id => $arValue)
132 {
133 if (is_array($arValue))
134 $values[$property_value_id] = $arValue["VALUE"];
135 else
136 $values[$property_value_id] = $arValue;
137
138 if(preg_match("/^n(\\d+)$/", $property_value_id, $match))
139 {
140 if($match[1] > $max_n)
141 $max_n = intval($match[1]);
142 }
143 }
144 }
145
147 if($settings["size"] > 1)
148 $size = ' size="'.$settings["size"].'"';
149 else
150 $size = '';
151
152 if($settings["width"] > 0)
153 $width = ' style="width:'.$settings["width"].'px"';
154 else
155 $width = '';
156
157 if($settings["multiple"]=="Y")
158 {
159 $bWasSelect = false;
160 $options = CIBlockPropertyElementList::GetOptionsHtml($arProperty, $values, $bWasSelect);
161
162 $html = '<input type="hidden" name="'.$strHTMLControlName["VALUE"].'[]" value="">';
163 $html .= '<select multiple name="'.$strHTMLControlName["VALUE"].'[]"'.$size.$width.'>';
164 if($arProperty["IS_REQUIRED"] != "Y")
165 $html .= '<option value=""'.(!$bWasSelect? ' selected': '').'>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_NO_VALUE").'</option>';
166 $html .= $options;
167 $html .= '</select>';
168 }
169 else
170 {
171 if(end($values) != "" || mb_substr((string)key($values), 0, 1) != "n")
172 $values["n".($max_n+1)] = "";
173
174 $name = $strHTMLControlName["VALUE"]."VALUE";
175
176 $html = '<table cellpadding="0" cellspacing="0" border="0" class="nopadding" width="100%" id="tb'.md5($name).'">';
177 foreach($values as $property_value_id=>$value)
178 {
179 $html .= '<tr><td>';
180
181 $bWasSelect = false;
182 $options = CIBlockPropertyElementList::GetOptionsHtml($arProperty, array($value), $bWasSelect);
183
184 $html .= '<select name="'.$strHTMLControlName["VALUE"].'['.$property_value_id.'][VALUE]"'.$size.$width.'>';
185 $html .= '<option value=""'.(!$bWasSelect? ' selected': '').'>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_NO_VALUE").'</option>';
186 $html .= $options;
187 $html .= '</select>';
188
189 $html .= '</td></tr>';
190 }
191 $html .= '</table>';
192
193 $html .= '<input type="button" value="'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_ADD").'" onClick="BX.IBlock.Tools.addNewRow(\'tb'.md5($name).'\', -1)">';
194 }
195 return $html;
196 }
197
198 public static function GetAdminFilterHTML($arProperty, $strHTMLControlName)
199 {
200 $lAdmin = new CAdminList($strHTMLControlName["TABLE_ID"]);
201 $lAdmin->InitFilter(array($strHTMLControlName["VALUE"]));
202 $filterValue = $GLOBALS[$strHTMLControlName["VALUE"]];
203
204 if(isset($filterValue) && is_array($filterValue))
205 $values = $filterValue;
206 else
207 $values = array();
208
209 $settings = CIBlockPropertyElementList::PrepareSettings($arProperty);
210 if($settings["size"] > 1)
211 $size = ' size="'.$settings["size"].'"';
212 else
213 $size = '';
214
215 if($settings["width"] > 0)
216 $width = ' style="width:'.$settings["width"].'px"';
217 else
218 $width = '';
219
220 $bWasSelect = false;
221 $options = CIBlockPropertyElementList::GetOptionsHtml($arProperty, $values, $bWasSelect);
222
223 $html = '<select multiple name="'.$strHTMLControlName["VALUE"].'[]"'.$size.$width.'>';
224 $html .= '<option value=""'.(!$bWasSelect? ' selected': '').'>'.Loc::getMessage("IBLOCK_PROP_ELEMENT_LIST_ANY_VALUE").'</option>';
225 $html .= $options;
226 $html .= '</select>';
227 return $html;
228 }
229
230 public static function GetUIFilterProperty($arProperty, $strHTMLControlName, &$fields)
231 {
232 $fields['type'] = 'list';
233 $fields['items'] = self::getItemsForUiFilter($arProperty);
234 $fields['operators'] = array(
235 'default' => '=',
236 'enum' => '@',
237 );
238 }
239
240 private static function getItemsForUiFilter($arProperty)
241 {
242 $items = array();
243 $settings = static::PrepareSettings($arProperty);
244
245 if ($settings["group"] === "Y")
246 {
247 $arElements = CIBlockPropertyElementList::GetElements($arProperty["LINK_IBLOCK_ID"]);
248 $arTree = CIBlockPropertyElementList::GetSections($arProperty["LINK_IBLOCK_ID"]);
249 foreach ($arElements as $i => $arElement)
250 {
251 if(
252 $arElement["IN_SECTIONS"] == "Y"
253 && array_key_exists($arElement["IBLOCK_SECTION_ID"], $arTree)
254 )
255 {
256 $arTree[$arElement["IBLOCK_SECTION_ID"]]["E"][] = $arElement;
257 unset($arElements[$i]);
258 }
259 }
260
261 // todo add <optgroup> for ui filter
262 foreach ($arTree as $arSection)
263 {
264 if (isset($arSection["E"]))
265 {
266 foreach ($arSection["E"] as $arItem)
267 {
268 $items[$arItem["ID"]] = $arItem["NAME"];
269 }
270 }
271 }
272 foreach ($arElements as $arItem)
273 {
274 $items[$arItem["ID"]] = $arItem["NAME"];
275 }
276
277 }
278 else
279 {
280 foreach (CIBlockPropertyElementList::GetElements($arProperty["LINK_IBLOCK_ID"]) as $arItem)
281 {
282 $items[$arItem["ID"]] = $arItem["NAME"];
283 }
284 }
285
286 return $items;
287 }
288
289 public static function GetPublicViewHTML($arProperty, $arValue, $strHTMLControlName)
290 {
291 static $cache = array();
292
293 $strResult = '';
294 $arValue['VALUE'] = intval($arValue['VALUE']);
295 if (0 < $arValue['VALUE'])
296 {
297 $viewMode = '';
298 $resultKey = '';
299 if (!empty($strHTMLControlName['MODE']))
300 {
301 switch ($strHTMLControlName['MODE'])
302 {
303 case 'CSV_EXPORT':
304 $viewMode = 'CSV_EXPORT';
305 $resultKey = 'ID';
306 break;
307 case 'EXTERNAL_ID':
308 $viewMode = 'EXTERNAL_ID';
309 $resultKey = '~XML_ID';
310 break;
311 case 'SIMPLE_TEXT':
312 $viewMode = 'SIMPLE_TEXT';
313 $resultKey = '~NAME';
314 break;
315 case 'ELEMENT_TEMPLATE':
316 $viewMode = 'ELEMENT_TEMPLATE';
317 $resultKey = '~NAME';
318 break;
319 case 'BIZPROC':
320 $viewMode = 'BIZPROC';
321 break;
322 }
323 }
324
325 if (!isset($cache[$arValue['VALUE']]))
326 {
327 $arFilter = [];
328 $intIBlockID = (int)$arProperty['LINK_IBLOCK_ID'];
329 if ($intIBlockID > 0)
330 $arFilter['IBLOCK_ID'] = $intIBlockID;
331 $arFilter['ID'] = $arValue['VALUE'];
332 if ($viewMode === '')
333 {
334 $arFilter['ACTIVE'] = 'Y';
335 $arFilter['ACTIVE_DATE'] = 'Y';
336 $arFilter['CHECK_PERMISSIONS'] = 'Y';
337 $arFilter['MIN_PERMISSION'] = 'R';
338 }
339 $rsElements = CIBlockElement::GetList(
340 array(),
341 $arFilter,
342 false,
343 false,
344 array("ID","IBLOCK_ID","NAME","DETAIL_PAGE_URL")
345 );
346 if (isset($strHTMLControlName['DETAIL_URL']))
347 {
348 $rsElements->SetUrlTemplates($strHTMLControlName['DETAIL_URL']);
349 }
350 $cache[$arValue['VALUE']] = $rsElements->GetNext(true, true);
351 unset($rsElements);
352 }
353 if (!empty($cache[$arValue['VALUE']]) && is_array($cache[$arValue['VALUE']]))
354 {
355 if ($viewMode !== '' && $resultKey !== '')
356 {
357 $strResult = $cache[$arValue['VALUE']][$resultKey];
358 }
359 else
360 {
361 $strResult = '<a href="'.$cache[$arValue['VALUE']]['DETAIL_PAGE_URL'].'">'.$cache[$arValue['VALUE']]['NAME'].'</a>';
362 }
363 }
364 }
365 return $strResult;
366 }
367
368 public static function GetOptionsHtml($arProperty, $values, &$bWasSelect)
369 {
370 $options = "";
371 $settings = CIBlockPropertyElementList::PrepareSettings($arProperty);
372 $bWasSelect = false;
373
374 if($settings["group"] === "Y")
375 {
376 $arElements = CIBlockPropertyElementList::GetElements($arProperty["LINK_IBLOCK_ID"]);
377 $arTree = CIBlockPropertyElementList::GetSections($arProperty["LINK_IBLOCK_ID"]);
378 foreach($arElements as $i => $arElement)
379 {
380 if(
381 $arElement["IN_SECTIONS"] == "Y"
382 && array_key_exists($arElement["IBLOCK_SECTION_ID"], $arTree)
383 )
384 {
385 $arTree[$arElement["IBLOCK_SECTION_ID"]]["E"][] = $arElement;
386 unset($arElements[$i]);
387 }
388 }
389
390 foreach($arTree as $arSection)
391 {
392 $margin = max((int)$arSection['DEPTH_LEVEL'], 1) - 1;
393 $options .= '<optgroup label="' . str_repeat(' . ', $margin) . $arSection['NAME'] . '">';
394 if(isset($arSection["E"]))
395 {
396 foreach($arSection["E"] as $arItem)
397 {
398 $options .= '<option value="'.$arItem["ID"].'"';
399 if(in_array($arItem["~ID"], $values))
400 {
401 $options .= ' selected';
402 $bWasSelect = true;
403 }
404 $options .= '>'.$arItem["NAME"].'</option>';
405 }
406 }
407 $options .= '</optgroup>';
408 }
409 foreach($arElements as $arItem)
410 {
411 $options .= '<option value="'.$arItem["ID"].'"';
412 if(in_array($arItem["~ID"], $values))
413 {
414 $options .= ' selected';
415 $bWasSelect = true;
416 }
417 $options .= '>'.$arItem["NAME"].'</option>';
418 }
419
420 }
421 else
422 {
423 foreach(CIBlockPropertyElementList::GetElements($arProperty["LINK_IBLOCK_ID"]) as $arItem)
424 {
425 $options .= '<option value="'.$arItem["ID"].'"';
426 if(in_array($arItem["~ID"], $values))
427 {
428 $options .= ' selected';
429 $bWasSelect = true;
430 }
431 $options .= '>'.$arItem["NAME"].'</option>';
432 }
433 }
434
435 return $options;
436 }
437
445 public static function GetExtendedValue($arProperty, $value)
446 {
447 $html = self::GetPublicViewHTML($arProperty, $value, array('MODE' => 'SIMPLE_TEXT'));
448 if($html <> '')
449 {
450 $text = htmlspecialcharsback($html);
451 return array(
452 'VALUE' => $text,
453 'UF_XML_ID' => $text,
454 );
455 }
456 return false;
457 }
458
459 public static function GetElements($IBLOCK_ID)
460 {
461 static $cache = array();
462 $IBLOCK_ID = intval($IBLOCK_ID);
463
464 if(!array_key_exists($IBLOCK_ID, $cache))
465 {
466 $cache[$IBLOCK_ID] = array();
467 if($IBLOCK_ID > 0)
468 {
469 $arSelect = array(
470 "ID",
471 "NAME",
472 "IN_SECTIONS",
473 "IBLOCK_SECTION_ID",
474 );
475 $arFilter = array (
476 "IBLOCK_ID"=> $IBLOCK_ID,
477 //"ACTIVE" => "Y",
478 "CHECK_PERMISSIONS" => "Y",
479 );
480 $arOrder = array(
481 "NAME" => "ASC",
482 "ID" => "ASC",
483 );
484 $rsItems = CIBlockElement::GetList($arOrder, $arFilter, false, false, $arSelect);
485 while($arItem = $rsItems->GetNext())
486 $cache[$IBLOCK_ID][] = $arItem;
487 }
488 }
489 return $cache[$IBLOCK_ID];
490 }
491
492 public static function GetSections($IBLOCK_ID)
493 {
494 static $cache = [];
495 $IBLOCK_ID = (int)$IBLOCK_ID;
496
497 if (!isset($cache[$IBLOCK_ID]))
498 {
499 $cache[$IBLOCK_ID] = [];
500 if ($IBLOCK_ID > 0)
501 {
502 $arSelect = [
503 'ID',
504 'IBLOCK_ID',
505 'NAME',
506 'DEPTH_LEVEL',
507 'LEFT_MARGIN',
508 ];
509 $arFilter = [
510 'IBLOCK_ID'=> $IBLOCK_ID,
511 //'ACTIVE' => 'Y',
512 'CHECK_PERMISSIONS' => 'Y',
513 ];
514 $arOrder = [
515 'LEFT_MARGIN' => 'ASC',
516 ];
517 $rsItems = CIBlockSection::GetList($arOrder, $arFilter, false, $arSelect);
518 while($arItem = $rsItems->GetNext())
519 {
520 $cache[$IBLOCK_ID][$arItem['ID']] = $arItem;
521 }
522 unset($arItem, $rsItems);
523 }
524 }
525
526 return $cache[$IBLOCK_ID];
527 }
528
529 public static function GetUIEntityEditorProperty($settings, $value)
530 {
531 return [
532 'type' => 'custom',
533 ];
534 }
535}
const TYPE_ELEMENT
Определения propertytable.php:68
const USER_TYPE_ELEMENT_LIST
Определения propertytable.php:80
static PrepareSettings($arProperty)
Определения prop_element_list.php:31
static GetOptionsHtml($arProperty, $values, &$bWasSelect)
Определения prop_element_list.php:368
static GetSettingsHTML($arProperty, $strHTMLControlName, &$arPropertyFields)
Определения prop_element_list.php:59
static GetPropertyFieldHtmlMulty($arProperty, $value, $strHTMLControlName)
Определения prop_element_list.php:125
static GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
Определения prop_element_list.php:97
static GetUserTypeDescription()
Определения prop_element_list.php:11
$options
Определения commerceml2.php:49
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
Определения file_new.php:677
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
$settings
Определения product_settings.php:43
font size
Определения invoice.php:442
$width
Определения html.php:68