1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
prop_xmlid.php
См. документацию.
1
<?php
2
3
use
Bitrix\Main\Localization\Loc
;
4
use
Bitrix\Iblock
;
5
6
class
CIBlockPropertyXmlID
7
{
9
const
USER_TYPE
=
Iblock\PropertyTable::USER_TYPE_XML_ID
;
10
11
public
static
function
GetUserTypeDescription
()
12
{
13
return
[
14
'PROPERTY_TYPE'
=>
Iblock\PropertyTable::TYPE_STRING
,
15
'USER_TYPE'
=>
Iblock\PropertyTable::USER_TYPE_XML_ID
,
16
'DESCRIPTION'
=> Loc::getMessage(
'IBLOCK_PROP_XMLID_DESC'
),
17
'GetPublicViewHTML'
=> [__CLASS__,
'GetPublicViewHTML'
],
18
'GetAdminListViewHTML'
=> [__CLASS__,
'GetAdminListViewHTML'
],
19
'GetPropertyFieldHtml'
=> [__CLASS__,
'GetPropertyFieldHtml'
],
20
'GetSettingsHTML'
=> [__CLASS__,
'GetSettingsHTML'
],
21
'GetUIEntityEditorProperty'
=> [__CLASS__,
'GetUIEntityEditorProperty'
],
22
'GetUIEntityEditorPropertyEditHtml'
=> [__CLASS__,
'GetUIEntityEditorPropertyEditHtml'
],
23
'GetUIEntityEditorPropertyViewHtml'
=> [__CLASS__,
'GetUIEntityEditorPropertyViewHtml'
],
24
];
25
}
26
27
public
static
function
GetPublicViewHTML
($arProperty, $value, $strHTMLControlName)
28
{
29
static
$cache =
array
();
30
if
(isset($strHTMLControlName[
'MODE'
]) && $strHTMLControlName[
"MODE"
] ==
"CSV_EXPORT"
)
31
{
32
return
$value[
"VALUE"
];
33
}
34
elseif
($value[
"VALUE"
] <>
''
)
35
{
36
if
(!isset($cache[$value[
"VALUE"
]]))
37
{
38
$db_res
= CIBlockElement::GetList(
39
array
(),
40
array
(
"=XML_ID"
=>$value[
"VALUE"
],
"SHOW_HISTORY"
=>
"Y"
),
41
false
,
42
false
,
43
array
(
"ID"
,
"IBLOCK_TYPE_ID"
,
"IBLOCK_ID"
,
"NAME"
,
"DETAIL_PAGE_URL"
)
44
);
45
$ar_res
=
$db_res
->GetNext();
46
if
(
$ar_res
)
47
$cache[$value[
"VALUE"
]] =
$ar_res
;
48
else
49
$cache[$value[
"VALUE"
]] = $value[
"VALUE"
];
50
}
51
52
if
(isset($strHTMLControlName[
'MODE'
]) && ($strHTMLControlName[
"MODE"
] ==
"SIMPLE_TEXT"
|| $strHTMLControlName[
"MODE"
] ==
'ELEMENT_TEMPLATE'
))
53
{
54
if
(is_array($cache[$value[
"VALUE"
]]))
55
return
$cache[$value[
"VALUE"
]][
"~NAME"
];
56
else
57
return
$cache[$value[
"VALUE"
]];
58
}
59
else
60
{
61
if
(is_array($cache[$value[
"VALUE"
]]))
62
return
'<a href="'
.$cache[$value[
"VALUE"
]][
"DETAIL_PAGE_URL"
].
'">'
.$cache[$value[
"VALUE"
]][
"NAME"
].
'</a>'
;
63
else
64
return
htmlspecialcharsex($cache[$value[
"VALUE"
]]);
65
}
66
}
67
else
68
{
69
return
''
;
70
}
71
}
72
73
public
static
function
GetAdminListViewHTML
($arProperty, $value, $strHTMLControlName)
74
{
75
static
$cache =
array
();
76
if
($value[
"VALUE"
] <>
''
)
77
{
78
if
(!array_key_exists($value[
"VALUE"
], $cache))
79
{
80
$db_res
= CIBlockElement::GetList(
81
array
(),
82
array
(
"=XML_ID"
=>$value[
"VALUE"
],
"SHOW_HISTORY"
=>
"Y"
),
83
false
,
84
false
,
85
array
(
"ID"
,
"IBLOCK_TYPE_ID"
,
"IBLOCK_ID"
,
"NAME"
)
86
);
87
$ar_res
=
$db_res
->GetNext();
88
if
(
$ar_res
)
89
$cache[$value[
"VALUE"
]] =
htmlspecialcharsbx
(
$ar_res
[
'NAME'
]).
90
' [<a href="'
.
91
'/bitrix/admin/iblock_element_edit.php?'
.
92
'type='
.urlencode(
$ar_res
[
'IBLOCK_TYPE_ID'
]).
93
'&IBLOCK_ID='
.$ar_res[
'IBLOCK_ID'
].
94
'&ID='
.$ar_res[
'ID'
].
95
'&lang='
.LANGUAGE_ID.
96
'" title="'
.Loc::getMessage(
"IBLOCK_PROP_EL_EDIT"
).
'">'
.
$ar_res
[
'ID'
].
'</a>]'
;
97
else
98
$cache[$value[
"VALUE"
]] =
htmlspecialcharsbx
($value[
"VALUE"
]);
99
}
100
return
$cache[$value[
"VALUE"
]];
101
}
102
else
103
{
104
return
' '
;
105
}
106
}
107
108
//PARAMETERS:
109
//$arProperty - b_iblock_property.*
110
//$value - array("VALUE","DESCRIPTION") -- here comes HTML form value
111
//strHTMLControlName - array("VALUE","DESCRIPTION")
112
//return:
113
//safe html
114
public
static
function
GetPropertyFieldHtml
($arProperty, $value, $strHTMLControlName)
115
{
116
$ar_res
=
false
;
117
if
($value[
"VALUE"
] <>
''
)
118
{
119
$db_res
= CIBlockElement::GetList(
120
array
(),
121
array
(
"=XML_ID"
=> $value[
"VALUE"
],
"SHOW_HISTORY"
=>
"Y"
),
122
false
,
123
false
,
124
array
(
"ID"
,
"IBLOCK_ID"
,
"NAME"
)
125
);
126
$ar_res
=
$db_res
->GetNext();
127
}
128
129
if
(!
$ar_res
)
130
$ar_res
=
array
(
"NAME"
=>
""
);
131
132
$arProperty[
"LINK_IBLOCK_ID"
] ??= 0;
133
$fixIBlock = $arProperty[
"LINK_IBLOCK_ID"
] > 0;
134
$windowTableId =
'iblockprop-'
.Iblock\PropertyTable::TYPE_ELEMENT.
'-'
.$arProperty[
'ID'
].
'-'
.$arProperty[
'LINK_IBLOCK_ID'
];
135
136
return
'<input name="'
.htmlspecialcharsbx($strHTMLControlName[
"VALUE"
]).
'" id="'
.
htmlspecialcharsbx
($strHTMLControlName[
"VALUE"
]).
'" value="'
.
htmlspecialcharsEx
($value[
"VALUE"
]).
'" size="20" type="text">'
.
137
'<input type="button" value="..." onClick="jsUtils.OpenWindow(\''
.CUtil::JSEscape(
'/bitrix/admin/iblock_element_search.php?lang='
.LANGUAGE_ID.
'&n='
.urlencode($strHTMLControlName[
"VALUE"
]).
'&get_xml_id=Y&a=b'
.($fixIBlock ?
'&iblockfix=y'
:
''
).
'&tableId='
.$windowTableId).
'\'
, 900, 700);
">'.
138
' <span id="
sp_
'.htmlspecialcharsbx($strHTMLControlName["VALUE"]).'
" >'.$ar_res['NAME'].'</span>';
139
}
140
141
public static function GetSettingsHTML($arProperty, $strHTMLControlName, &$arPropertyFields)
142
{
143
$arPropertyFields = array(
144
"
HIDE
" => array("
ROW_COUNT
", "
COL_COUNT
", "
WITH_DESCRIPTION
"),
145
);
146
return '';
147
}
148
149
public static function GetUIEntityEditorProperty($settings, $value)
150
{
151
return [
152
'type' => 'custom',
153
];
154
}
155
156
public static function GetUIEntityEditorPropertyEditHtml(array $params = []) : string
157
{
158
$settings = $params['SETTINGS'] ?? [];
159
160
\Bitrix\Main\UI\Extension::load(['ui.entity-selector', 'ui.buttons', 'ui.forms']);
161
$fieldName = htmlspecialcharsbx($params['FIELD_NAME']);
162
$containerId = $fieldName . '_container';
163
$inputsContainerId = $fieldName . '_inputs_container';
164
165
$isMultiple = $settings['MULTIPLE'] === 'Y';
166
$isMultiple = CUtil::PhpToJSObject($isMultiple);
167
168
if (!is_array($params['VALUE']))
169
{
170
$params['VALUE'] = (!empty($params['VALUE'])) ? [$params['VALUE']] : [];
171
}
172
173
$preselectedItems = [];
174
foreach ($params['VALUE'] as $value)
175
{
176
if (!$value)
177
{
178
continue;
179
}
180
$element = self::getElementByXmlId($value);
181
if ($element)
182
{
183
$preselectedItems[] = ['iblock-property-element-xml', (string)$element['ID']];
184
}
185
}
186
187
$preselectedItems = CUtil::PhpToJSObject($preselectedItems);
188
$messages = [
189
'NOT_FOUND' => Loc::getMessage('BT_UT_XML_ID_SEARCH_NOT_FOUND'),
190
'CHANGE_QUERY' => Loc::getMessage('BT_UT_XML_ID_SEARCH_CHANGE_QUERY'),
191
'ENTER_QUERY' => Loc::getMessage('BT_UT_XML_ID_SEARCH_ENTER_QUERY'),
192
'ENTER_QUERY_SUBTITLE' => Loc::getMessage('BT_UT_XML_ID_SEARCH_ENTER_QUERY_SUBTITLE'),
193
];
194
$propertyType = Iblock\PropertyTable::USER_TYPE_XML_ID;
195
196
return <<<HTML
197
<div id="
{$containerId}
" name="
{$containerId}
"></div>
198
<div id="
{$inputsContainerId}
" name="
{$inputsContainerId}
"></div>
199
<script>
200
(function() {
201
var selector = new BX.UI.EntitySelector.TagSelector({
202
id: '{$containerId}',
203
multiple: {$isMultiple},
204
205
dialogOptions: {
206
height: 300,
207
id: '{$containerId}',
208
multiple: {$isMultiple},
209
preselectedItems: {$preselectedItems},
210
entities: [
211
{
212
id: 'iblock-property-element-xml',
213
dynamicLoad: true,
214
dynamicSearch: true,
215
options: {
216
propertyType: '{$propertyType}',
217
},
218
}
219
],
220
searchOptions: {
221
allowCreateItem: false,
222
},
223
searchTabOptions: {
224
stub: true,
225
stubOptions: {
226
title: '{$messages['NOT_FOUND']}',
227
subtitle: '{$messages['CHANGE_QUERY']}',
228
arrow: false,
229
}
230
},
231
recentTabOptions: {
232
stub: true,
233
stubOptions: {
234
title: '{$messages['ENTER_QUERY']}',
235
subtitle: '{$messages['ENTER_QUERY_SUBTITLE']}',
236
arrow: false,
237
}
238
},
239
events: {
240
'Item:onSelect': setSelectedInputs.bind(this, 'Item:onSelect'),
241
'Item:onDeselect': setSelectedInputs.bind(this, 'Item:onDeselect'),
242
},
243
},
244
})
245
246
function setSelectedInputs(eventName, event)
247
{
248
var dialog = event.getData().item.getDialog();
249
if (!dialog.isMultiple())
250
{
251
dialog.hide();
252
}
253
var selectedItems = dialog.getSelectedItems();
254
if (Array.isArray(selectedItems))
255
{
256
var htmlInputs = '';
257
selectedItems.forEach(function(item)
258
{
259
htmlInputs +=
260
'<input type="
hidden
" name="
{$fieldName}[]
" value="
' + BX.util.htmlspecialchars(item['
customData
'].get('
xmlId
')) + '
" />'
261
;
262
});
263
if (htmlInputs === '')
264
{
265
htmlInputs =
266
'<input type="
hidden
" name="
{$fieldName}[]
" value="
" />'
267
;
268
}
269
document.getElementById('{$inputsContainerId}').innerHTML = htmlInputs;
270
BX.Event.EventEmitter.emit('onChangeIblockElement');
271
}
272
}
273
274
selector.renderTo(document.getElementById("
{$containerId}
"));
275
})();
276
277
</script>
278
HTML;
279
}
280
281
public static function GetUIEntityEditorPropertyViewHtml(array $params = []): string
282
{
283
$result = '';
284
285
if (empty($params['VALUE']))
286
{
287
return '';
288
}
289
290
if (!is_array($params['VALUE']))
291
{
292
$params['VALUE'] = [$params['VALUE']];
293
}
294
295
foreach ($params['VALUE'] as $value)
296
{
297
$filter = [
298
'CHECK_PERMISSIONS' => 'Y',
299
'MIN_PERMISSION' => 'R',
300
'XML_ID' => $value,
301
];
302
$element = CIBlockElement::GetList(
303
[],
304
$filter,
305
false,
306
false,
307
['ID', 'XML_ID', 'IBLOCK_ID', 'NAME']
308
)->Fetch();
309
310
$result .= htmlspecialcharsbx($element['NAME']) . '<br>';
311
}
312
313
return $result;
314
}
315
320
private static function getElementByXmlId(string $xmlId): bool|array
321
{
322
$filter = [
323
'CHECK_PERMISSIONS' => 'Y',
324
'MIN_PERMISSION' => 'R',
325
'=XML_ID' => $xmlId,
326
'ACTIVE' => 'Y',
327
];
328
329
return \CIBlockElement::GetList(
330
[],
331
$filter,
332
false,
333
['nTopCount' => 1],
334
['ID', 'NAME', 'XML_ID']
335
)->Fetch();
336
}
337
}
$db_res
$db_res
Определения
options_user_settings.php:8
$ar_res
$ar_res
Определения
options_user_settings_set.php:16
Bitrix\Iblock\PropertyTable\TYPE_STRING
const TYPE_STRING
Определения
propertytable.php:65
Bitrix\Iblock\PropertyTable\USER_TYPE_XML_ID
const USER_TYPE_XML_ID
Определения
propertytable.php:77
Bitrix\Main\Localization\Loc
Определения
loc.php:12
CIBlockPropertyXmlID
Определения
prop_xmlid.php:7
CIBlockPropertyXmlID\GetPublicViewHTML
static GetPublicViewHTML($arProperty, $value, $strHTMLControlName)
Определения
prop_xmlid.php:27
CIBlockPropertyXmlID\GetPropertyFieldHtml
static GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
Определения
prop_xmlid.php:114
CIBlockPropertyXmlID\GetUserTypeDescription
static GetUserTypeDescription()
Определения
prop_xmlid.php:11
CIBlockPropertyXmlID\GetAdminListViewHTML
static GetAdminListViewHTML($arProperty, $value, $strHTMLControlName)
Определения
prop_xmlid.php:73
CIBlockPropertyXmlID\USER_TYPE
const USER_TYPE
Определения
prop_xmlid.php:9
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
htmlspecialcharsEx
htmlspecialcharsEx($str)
Определения
tools.php:2685
htmlspecialcharsbx
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения
tools.php:2701
Bitrix\Iblock
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
bitrix
modules
iblock
classes
general
prop_xmlid.php
Создано системой
1.14.0