1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PropertyGridProvider.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Integration\UI\Grid\Property;
4
5use Bitrix\Iblock\Helpers\Admin\Property;
6use Bitrix\Iblock\Integration\UI\Grid\General\BaseProvider;
7use Bitrix\Main\Grid\Column\Type;
8use Bitrix\Main\Grid\Panel;
9use Bitrix\Main\Localization\Loc;
10use Bitrix\Main\Text\HtmlFilter;
11use Bitrix\Main\Type\Collection;
12
13use CIBlockProperty;
14
16{
17 private int $iblockId;
18 private LinksBuilder $linksBuilder;
19
24 public function __construct(int $iblockId, LinksBuilder $linksBuilder)
25 {
26 $this->iblockId = $iblockId;
27 $this->linksBuilder = $linksBuilder;
28 }
29
33 public function getId(): string
34 {
35 return "iblock_property_{$this->iblockId}";
36 }
37
45 public function getFieldName(string $fieldId): ?string
46 {
47 $columns = $this->getColumns();
48 foreach ($columns as $item)
49 {
50 if ($item['id'] === $fieldId)
51 {
52 return (string)$item['name'];
53 }
54 }
55
56 return null;
57 }
58
62 public function getColumns(): array
63 {
64 return [
65 [
66 'id' => 'ID',
67 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ID'),
68 'type' => 'int',
69 'sort' => 'ID',
70 ],
71 [
72 'id' => 'NAME',
73 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_NAME'),
74 'sort' => 'NAME',
75 'default' => true,
76 'editable' => true,
77 ],
78 [
79 'id' => 'CODE',
80 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_CODE'),
81 'sort' => 'CODE',
82 'editable' => true,
83 ],
84 [
85 'id' => 'PROPERTY_TYPE',
86 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_PROPERTY_TYPE'),
87 'sort' => 'PROPERTY_TYPE',
88 'type' => 'list',
89 'default' => true,
90 'editable' => false,
91 ],
92 [
93 'id' => 'SORT',
94 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_SORT'),
95 'sort' => 'SORT',
96 'type' => 'int',
97 'default' => true,
98 'editable' => true,
99 ],
100 [
101 'id' => 'ACTIVE',
102 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTIVE'),
103 'sort' => 'ACTIVE',
104 'type' => 'checkbox',
105 'default' => true,
106 'editable' => true,
107 ],
108 [
109 'id' => 'IS_REQUIRED',
110 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_IS_REQUIRED'),
111 'sort' => 'IS_REQUIRED',
112 'type' => 'checkbox',
113 'default' => true,
114 'editable' => true,
115 ],
116 [
117 'id' => 'MULTIPLE',
118 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_MULTIPLE'),
119 'sort' => 'MULTIPLE',
120 'type' => 'checkbox',
121 'default' => true,
122 'editable' => true,
123 ],
124 [
125 'id' => 'SEARCHABLE',
126 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_SEARCHABLE'),
127 'sort' => 'SEARCHABLE',
128 'type' => 'checkbox',
129 'default' => true,
130 'editable' => true,
131 ],
132 [
133 'id' => 'FILTRABLE',
134 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_FILTRABLE'),
135 'sort' => 'FILTRABLE',
136 'type' => 'checkbox',
137 'editable' => true,
138 ],
139 [
140 'id' => 'XML_ID',
141 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_XML_ID'),
142 'sort' => 'XML_ID',
143 'editable' => true,
144 ],
145 [
146 'id' => 'WITH_DESCRIPTION',
147 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_WITH_DESCRIPTION'),
148 'sort' => 'WITH_DESCRIPTION',
149 'type' => 'checkbox',
150 'editable' => true,
151 ],
152 [
153 'id' => 'HINT',
154 'name' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_HINT'),
155 ],
156 ];
157 }
158
162 protected function getRowActions(array $row, bool $isEditable): array
163 {
164 $id = (int)$row['ID'];
165
166 $result = [
167 [
168 'TEXT' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_OPEN'),
169 'HREF' => $this->linksBuilder->getActionOpenLink($id),
170 'ONCLICK' => $this->linksBuilder->getActionOpenClick($id),
171 'DEFAULT' => true,
172 ],
173 ];
174
175 if ($isEditable)
176 {
177 $result[] = [
178 'TEXT' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_DELETE'),
179 'HREF' => $this->linksBuilder->getActionDeleteLink($id),
180 'ONCLICK' => $this->linksBuilder->getActionDeleteClick($id),
181 ];
182 }
183
184 return $result;
185 }
186
192 private function getPropertyTypeItems(): array
193 {
194 $result = Property::getBaseTypeList(true);
195
196 $userTypes = CIBlockProperty::GetUserType();
197 Collection::sortByColumn($userTypes, [
198 'DESCRIPTION' => SORT_STRING,
199 ]);
200
201 foreach ($userTypes as $type => $item)
202 {
203 $key = "{$item['PROPERTY_TYPE']}:{$type}";
204 $result[$key] = $item['DESCRIPTION'];
205 }
206
207 return $result;
208 }
209
213 protected function getRowColumns(array $row): array
214 {
215 $result = parent::getRowColumns($row);
216
217 // prepare property type
218 if (isset($result['PROPERTY_TYPE']))
219 {
220 $type = $row['PROPERTY_TYPE'] ?? null;
221 if ($type)
222 {
223 $userType = $row['USER_TYPE'] ?? null;
224 if ($userType)
225 {
226 $type .= ':' . $userType;
227 }
228
229 $typeNames = $this->getPropertyTypeItems();
230 $result['PROPERTY_TYPE'] = $typeNames[$type] ?? null;
231 }
232 }
233
234 return $result;
235 }
236
244 public function prepareRow(array $rawRow): array
245 {
246 foreach($this->getColumns() as $field)
247 {
248 $id = $field['id'];
249 $type = $field['type'] ?? Type::TEXT;
250 switch ($type)
251 {
252 case Type::TEXT:
253 if (isset($rawRow[$id]))
254 {
255 $rawRow[$id] = HtmlFilter::encode($rawRow[$id]);
256 }
257 break;
258 case Type::INT:
259 if (isset($rawRow[$id]))
260 {
261 $rawRow[$id] = (int)$rawRow[$id];
262 }
263 break;
264 }
265 }
266
267 return parent::prepareRow($rawRow);
268 }
269
275 public function getActionPanel(): ?array
276 {
277 $items = [];
278 $items[] = $this->getRemoveActionItem();
279 $items[] = $this->getEditActionItem();
280
281 return [
282 'GROUPS' => [
283 [
284 'ITEMS' => $items,
285 ],
286 ],
287 ];
288 }
289
290 protected function getRemoveActionItem(): array
291 {
292 $onchange = new Panel\Snippet\Onchange();
293 $onchange->addAction([
294 'ACTION' => Panel\Actions::CALLBACK,
295 'CONFIRM' => true,
296 'CONFIRM_APPLY_BUTTON' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_CONFIRM_APPLY_REMOVE_BUTTON_TEXT'),
297 'CONFIRM_MESSAGE' => Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_CONFIRM_MESSAGE_REMOVE'),
298 'DATA' => [
299 [
300 'JS' => 'Grid.removeSelected()',
301 ],
302 ]
303 ]);
304
305 $removeButton = new Panel\Snippet\Button();
306 $removeButton->setClass(Panel\DefaultValue::REMOVE_BUTTON_CLASS)
308 ->setOnchange($onchange)
309 ->setText(Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_DELETE'))
310 ->setTitle(Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_DELETE_TITLE'))
311 ;
312
313 return $removeButton->toArray();
314 }
315
316 protected function getEditActionItem(): array
317 {
318 $snippet = new Panel\Snippet();
319
320 $actions = [];
321 $actions[] = [
322 'ACTION' => Panel\Actions::CREATE,
323 'DATA' => [
324 $snippet->getSaveEditButton(),
325 $snippet->getCancelEditButton(),
326 ],
327 ];
328 $actions[] = [
329 'ACTION' => Panel\Actions::CALLBACK,
330 'DATA' => [
331 [
332 'JS' => 'Grid.editSelected()',
333 ],
334 ],
335 ];
336 $actions[] = [
338 'DATA' => [
339 [
341 ],
342 [
344 ],
345 ],
346 ];
347
348 $editButton = new Panel\Snippet\Button();
349 $editButton->setClass(Panel\DefaultValue::EDIT_BUTTON_CLASS);
350 $editButton->setId(Panel\DefaultValue::EDIT_BUTTON_ID);
351 $editButton->setText(Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_EDIT'));
352 $editButton->setOnchange(new Panel\Snippet\Onchange($actions));
353 $editButton->setTitle(Loc::getMessage('IBLOCK_UI_GRID_PROPERTY_PROVIDER_ACTION_EDIT_TITLE'));
354
355 return $editButton->toArray();
356 }
357}
$type
Определения options.php:106
__construct(int $iblockId, LinksBuilder $linksBuilder)
Определения PropertyGridProvider.php:24
const HIDE_ALL_EXPECT
Определения actions.php:22
const CALLBACK
Определения actions.php:20
const CREATE
Определения actions.php:14
</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
if(empty($signedUserToken)) $key
Определения quickway.php:257
$items
Определения template.php:224