1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
groupaction.php
См. документацию.
1<?php
3
8
15{
16 public const GRID_TYPE_UI = 'main.ui.grid';
17 public const GRID_TYPE_LIST = 'adminList';
18 public const GRID_TYPE_SUBLIST = 'subList';
19
20 private const PREFIX_ID = 'iblock_grid_action_';
21
23 protected $entityId = '';
24
25 protected $gridType = self::GRID_TYPE_UI;
26
28 protected $options = [];
29
31 protected $iblockId = null;
32
34 protected $iblockConfig = [
35 'SECTIONS' => 'N',
37 ];
38
40 protected $mainSnippet = null;
41
43 protected $request = null;
44
46 protected $sections = null;
47
48 protected $actionHandlers = [];
49
50 public function __construct(array $options)
51 {
52 $this->options = $options;
53
54 $this->entityId = $options['ENTITY_ID'];
55 $this->iblockId = $options['IBLOCK_ID'];
56
57 if (isset($options['GRID_TYPE']))
58 {
59 $this->setGridType($options['GRID_TYPE']);
60 }
61
62 $this->mainSnippet = new Main\Grid\Panel\Snippet();
63 $this->request = Main\Context::getCurrent()->getRequest();
64
65 $this->initConfig();
66
67 $this->initActions();
68 }
69
74 public function getList(?array $actions = null): array
75 {
76 $result = [];
77
78 $actions ??= array_keys($this->actionHandlers);
79
80 if (!empty($actions))
81 {
82 foreach ($actions as $code => $params)
83 {
84 if (is_string($params))
85 {
86 $code = $params;
87 $params = [];
88 }
89 if (is_string($code) && is_array($params))
90 {
91 $row = $this->get($code, $params);
92 if ($row !== null)
93 {
94 $result[$code] = $row;
95 }
96 }
97 }
98 unset($row, $code, $params);
99 }
100
101 return $result;
102 }
103
109 public function get(string $code, array $params = [])
110 {
111 $code = trim($code);
112 if ($code === '' || !isset($this->actionHandlers[$code]))
113 {
114 return null;
115 }
116
117 $method = 'action'.$this->actionHandlers[$code].'Panel';
118 if (is_callable([$this, $method]))
119 {
120 return call_user_func_array([$this, $method], [$params]);
121 }
122
123 return [];
124 }
125
130 public function getRequest(string $code): ?array
131 {
132 $code = trim($code);
133 if ($code === '' || !isset($this->actionHandlers[$code]))
134 {
135 return null;
136 }
137
138 $method = 'action'.$this->actionHandlers[$code].'Request';
139 if (is_callable([$this, $method]))
140 {
141 return call_user_func_array([$this, $method], []);
142 }
143
144 return [];
145 }
146
150 public function getEntityId(): string
151 {
152 return $this->entityId;
153 }
154
158 public function getIblockId(): int
159 {
160 return $this->iblockId;
161 }
162
166 public function getOptions(): array
167 {
168 return $this->options;
169 }
170
174 protected function initConfig()
175 {
177 'select' => [
178 'ID',
179 'SECTION_CHOOSER',
180 'SECTIONS' => 'TYPE.SECTIONS'
181 ],
182 'filter' => ['=ID' => $this->iblockId],
183 ]);
184 $row = $iterator->fetch();
185 if (!empty($row))
186 {
187 $this->iblockConfig['SECTIONS'] = $row['SECTIONS'];
188 $this->iblockConfig['SECTION_CHOOSER'] = $row['SECTION_CHOOSER'];
189 }
190 unset($row, $iterator);
191 }
192
196 protected function initActions(): void
197 {
198 $this->actionHandlers = $this->getActionHandlers();
199 }
200
205 protected function setGridType(string $value): void
206 {
207 if (
208 $value === self::GRID_TYPE_UI
209 || $value === self::GRID_TYPE_LIST
210 || $value === self::GRID_TYPE_SUBLIST
211 )
212 {
213 $this->gridType = $value;
214 }
215 }
216
220 public function getGridType(): string
221 {
222 return $this->gridType;
223 }
224
228 public function isUiGrid(): bool
229 {
230 return $this->getGridType() === self::GRID_TYPE_UI;
231 }
232
255
259 public function getDefaultApplyAction(): array
260 {
261 return ['JS' => "BX.adminUiList.SendSelected('{$this->getEntityId()}')"];
262 }
263
268 public function getElementId(string $id): string
269 {
270 return self::PREFIX_ID.$this->getEntityId().'_'.strtolower($id);
271 }
272
278 {
279 $result = $this->mainSnippet->getApplyButton([]);
280 $result['id'] = $this->getElementId($params['APPLY_BUTTON_ID']);
281 $this->mainSnippet->setButtonActions(
282 $result,
283 [
284 [
285 'ACTION' => Main\Grid\Panel\Actions::CALLBACK,
286 'DATA' => [
287 $this->getDefaultApplyAction(),
288 ],
289 ],
290 ]
291 );
292 return $result;
293 }
294
300 {
301 $confirmMessage = null;
302 if (
303 isset($params['CONFIRM_MESSAGE'])
304 && is_string($params['CONFIRM_MESSAGE'])
305 && $params['CONFIRM_MESSAGE'] !== ''
306 )
307 {
308 $confirmMessage = $params['CONFIRM_MESSAGE'];
309 }
310 elseif (
311 isset($params['DEFAULT_CONFIRM_MESSAGE'])
312 && is_string($params['DEFAULT_CONFIRM_MESSAGE'])
313 && $params['DEFAULT_CONFIRM_MESSAGE'] !== ''
314 )
315 {
316 $confirmMessage = $params['DEFAULT_CONFIRM_MESSAGE'];
317 }
318
319 $result = $this->mainSnippet->getApplyButton([]);
320 $result['id'] = $this->getElementId($params['APPLY_BUTTON_ID']);
321 $this->mainSnippet->setButtonActions(
322 $result,
323 [
324 [
325 'ACTION' => Main\Grid\Panel\Actions::CALLBACK,
326 'CONFIRM' => true,
327 'CONFIRM_MESSAGE' => $confirmMessage,
328 'DATA' => [
329 $this->getDefaultApplyAction(),
330 ],
331 ],
332 ]
333 );
334
335 return $result;
336 }
337
341 protected function loadSections(): void
342 {
343 if ($this->sections === null)
344 {
345 $this->sections = [];
346 if ($this->iblockId > 0)
347 {
348 $iterator = \CIBlockSection::getTreeList(
349 ['IBLOCK_ID' => $this->iblockId],
350 ['ID', 'NAME', 'DEPTH_LEVEL', 'LEFT_MARGIN']
351 );
352 while ($row = $iterator->Fetch())
353 {
354 $this->sections[] = [
355 'NAME' => str_repeat(' . ', $row['DEPTH_LEVEL']).$row['NAME'],
356 'VALUE' => $row['ID']
357 ];
358 }
359 unset($row, $iterator);
360 }
361 }
362 }
363
368 protected function getSections(bool $addTop = false): array
369 {
370 $this->loadSections();
372 if ($addTop)
373 {
374 $result = array_merge(
375 [
376 [
377 'NAME' => Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_MESS_SECTION_TOP_LEVEL'),
378 'VALUE' => '0',
379 ],
380 ],
381 $result
382 );
383 }
384 return $result;
385 }
386
392 {
393 return [
394 'name' => $action['NAME'],
395 'type' => 'multicontrol',
396 'action' => [
397 [
399 ],
400 [
402 'DATA' => [
403 [
405 'ID' => $this->getElementId($action['SECTION_LIST_ID']),
406 'NAME' => 'section_to_move',
407 'ITEMS' => $this->getSections(),
408 ],
409 $this->getApplyButton($action),
410 ],
411 ],
412 ],
413 ];
414 }
415
421 {
422 return [
423 'name' => $action['NAME'],
424 'type' => 'multicontrol',
425 'action' => [
426 [
428 ],
429 [
431 'DATA' => [
432 [
434 'ID' => '',
435 'NAME' => '',
436 'TITLE' => '',
437 ],
438 /*[
439 'TYPE' => Main\Grid\Panel\Types::DATE,
440 'ID' => '',
441 'NAME' => ''
442 ], */
443 [
445 'ID' => '',
446 'NAME' => ''
447 ],
448 $this->getApplyButton($action)
449 ]
450 ]
451 ]
452 ];
453 }
454
460 {
461 return [
462 'name' => $action['NAME'],
463 'type' => 'multicontrol',
464 'action' => [
465 [
467 ],
468 [
470 'DATA' => [
471 [
473 'ID' => $this->getElementId($action['SECTION_LIST_ID']),
474 'NAME' => 'section_to_move',
475 'ITEMS' => $this->getSections(true)
476 ],
477 $this->getApplyButton($action)
478 ]
479 ]
480 ]
481 ];
482 }
483
488 protected function actionEditPanel(array $params = []): string
489 {
490 return (isset($params['NAME']) && $params['NAME'] != ''
491 ? $params['NAME']
492 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_EDIT')
493 );
494 }
495
500 protected function actionSelectAllPanel(array $params = []): bool
501 {
502 return true;
503 }
504
509 protected function actionDeletePanel(array $params = []): string
510 {
511 return (isset($params['NAME']) && $params['NAME'] != ''
512 ? $params['NAME']
513 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_DELETE')
514 );
515 }
516
521 protected function actionActivatePanel(array $params = []): string
522 {
523 return (isset($params['NAME']) && $params['NAME'] != ''
524 ? $params['NAME']
525 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ACTIVATE_MSGVER_2')
526 );
527 }
528
533 protected function actionDeactivatePanel(array $params = []): string
534 {
535 return (isset($params['NAME']) && $params['NAME'] != ''
536 ? $params['NAME']
537 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_DEACTIVATE_MSGVER_2')
538 );
539 }
540
545 protected function actionClearCounterPanel(array $params = [])
546 {
547 $name = (isset($params['NAME']) && $params['NAME'] !== ''
548 ? $params['NAME']
549 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_CLEAR_COUNTER')
550 );
551
552 $params['APPLY_BUTTON_ID'] = 'clear_counter_confirm';
553 $params['DEFAULT_CONFIRM_MESSAGE'] = Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_CLEAR_COUNTER_CONFIRM');
554
555 if ($this->isUiGrid())
556 {
557 return [
558 'name' => $name,
559 'type' => 'multicontrol',
560 'action' => [
561 [
563 ],
564 [
566 'DATA' => [$this->getApplyButtonWithConfirm($params)]
567 ]
568 ]
569 ];
570 }
571 else
572 {
573 return $name;
574 }
575 }
576
582 {
583 $name = (isset($params['NAME']) && $params['NAME'] !== ''
584 ? $params['NAME']
585 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_CODE_TRANSLITERATION_MSGVER_1')
586 );
587
588 $params['APPLY_BUTTON_ID'] = 'code_translit_confirm';
589 $params['DEFAULT_CONFIRM_MESSAGE'] = Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_CODE_TRANSLITERATION_CONFIRM');
590
591 if ($this->isUiGrid())
592 {
593 return [
594 'name' => $name,
595 'type' => 'multicontrol',
596 'action' => [
597 [
599 ],
600 [
602 'DATA' => [$this->getApplyButtonWithConfirm($params)],
603 ],
604 ],
605 ];
606 }
607 else
608 {
609 return $name;
610 }
611 }
612
617 protected function actionAdjustSectionPanel(array $params = []): ?array
618 {
619 if (!$this->isUiGrid())
620 {
621 return null;
622 }
623 if ($this->iblockConfig['SECTIONS'] != 'Y')
624 {
625 return null;
626 }
627 if (!isset($params['NAME']) || $params['NAME'] == '')
628 {
629 $params['NAME'] = Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ADJUST_SECTION');
630 }
631
632 $params['APPLY_BUTTON_ID'] = 'send_adjust_list';
633 if ($this->iblockConfig['SECTION_CHOOSER'] == Iblock\IblockTable::SECTION_CHOOSER_PATH)
634 {
635 $params['SECTION_LIST_ID'] = 'set_sections';
636 return $this->getAdjustSectionList($params);
637 }
638 else
639 {
640 $params['SECTION_LIST_ID'] = 'set_sections';
641 return $this->getAdjustSectionList($params);
642 }
643 }
644
648 protected function actionAdjustSectionRequest(): ?array
649 {
650 $sectionId = $this->request->get('section_to_move');
651 return (is_string($sectionId) ? ['SECTION_ID' => $sectionId] : null);
652 }
653
658 protected function actionAddSectionPanel(array $params = []): ?array
659 {
660 if (!$this->isUiGrid())
661 {
662 return null;
663 }
664 if ($this->iblockConfig['SECTIONS'] != 'Y')
665 {
666 return null;
667 }
668 if (!isset($params['NAME']) || $params['NAME'] === '')
669 {
670 $params['NAME'] = Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ADD_SECTION');
671 }
672
673 $params['APPLY_BUTTON_ID'] = 'send_add_list';
674 if ($this->iblockConfig['SECTION_CHOOSER'] == Iblock\IblockTable::SECTION_CHOOSER_PATH)
675 {
676 $params['SECTION_LIST_ID'] = 'additional_sections';
677 return $this->getAddSectionList($params);
678 }
679 else
680 {
681 $params['SECTION_LIST_ID'] = 'additional_sections';
682 return $this->getAddSectionList($params);
683 }
684 }
685
689 protected function actionAddSectionRequest(): ?array
690 {
691 $sectionId = $this->request->get('section_to_move');
692
693 return (is_string($sectionId) ? ['SECTION_ID' => $sectionId] : null);
694 }
695
700 protected function actionElementUnlockPanel(array $params = []): string
701 {
702 return (isset($params['NAME']) && $params['NAME'] !== ''
703 ? $params['NAME']
704 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ELEMENT_UNLOCK')
705 );
706 }
707
712 protected function actionElementLockPanel(array $params = []): string
713 {
714 return (isset($params['NAME']) && $params['NAME'] !== ''
715 ? $params['NAME']
716 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ELEMENT_LOCK')
717 );
718 }
719
725 {
726 if (!Loader::includeModule('workflow'))
727 {
728 return null;
729 }
730
731 $name = (isset($params['NAME']) && $params['NAME'] !== ''
732 ? $params['NAME']
733 : Loc::getMessage('IBLOCK_GRID_PANEL_ACTION_ELEMENT_WORKFLOW_STATUS')
734 );
735
736 $statusList = [];
737 $iterator = \CWorkflowStatus::getDropDownList('N', 'desc');
738 while ($row = $iterator->Fetch())
739 {
740 $statusList[] = [
741 'NAME' => $row['REFERENCE'],
742 'VALUE' => $row['REFERENCE_ID'],
743 ];
744 }
745 unset($row, $iterator);
746 if (empty($statusList))
747 {
748 return null;
749 }
750
751 $params['APPLY_BUTTON_ID'] = 'send_workflow_status';
752 $data = [];
753 $data[] = [
755 'ID' => $this->getElementId('workflow_status'),
756 'NAME' => 'wf_status_id',
757 'ITEMS' => $statusList,
758 ];
759 if ($this->isUiGrid())
760 {
761 $data[] = $this->getApplyButton($params);
762 }
763
764 return [
765 'name' => $name,
766 'type' => 'multicontrol',
767 'action' => [
768 [
770 ],
771 [
773 'DATA' => $data,
774 ],
775 ],
776 ];
777 }
778
783 {
784 $result = $this->request->get('wf_status_id');
785
786 return (is_string($result) ? ['WF_STATUS_ID' => $result] : null);
787 }
788}
const ELEMENT_LOCK
Определения actiontype.php:15
const ELEMENT_UNLOCK
Определения actiontype.php:16
const CLEAR_COUNTER
Определения actiontype.php:9
const DEACTIVATE
Определения actiontype.php:12
const DELETE
Определения actiontype.php:8
const ELEMENT_WORKFLOW_STATUS
Определения actiontype.php:17
const ACTIVATE
Определения actiontype.php:11
const MOVE_TO_SECTION
Определения actiontype.php:13
const SELECT_ALL
Определения actiontype.php:7
const ADD_TO_SECTION
Определения actiontype.php:14
const CODE_TRANSLIT
Определения actiontype.php:10
getSections(bool $addTop=false)
Определения groupaction.php:368
actionElementLockPanel(array $params=[])
Определения groupaction.php:712
getAddSectionList(array $action)
Определения groupaction.php:391
__construct(array $options)
Определения groupaction.php:50
actionDeactivatePanel(array $params=[])
Определения groupaction.php:533
getApplyButton(array $params)
Определения groupaction.php:277
actionAddSectionPanel(array $params=[])
Определения groupaction.php:658
actionSelectAllPanel(array $params=[])
Определения groupaction.php:500
actionActivatePanel(array $params=[])
Определения groupaction.php:521
getAdjustSectionList(array $action)
Определения groupaction.php:459
actionElementWorkflowStatusPanel(array $params=[])
Определения groupaction.php:724
actionDeletePanel(array $params=[])
Определения groupaction.php:509
actionClearCounterPanel(array $params=[])
Определения groupaction.php:545
actionEditPanel(array $params=[])
Определения groupaction.php:488
getApplyButtonWithConfirm(array $params)
Определения groupaction.php:299
getList(?array $actions=null)
Определения groupaction.php:74
getRequest(string $code)
Определения groupaction.php:130
actionCodeTranslitPanel(array $params=[])
Определения groupaction.php:581
actionAdjustSectionPanel(array $params=[])
Определения groupaction.php:617
getElementId(string $id)
Определения groupaction.php:268
getAddSectionDialog(array $action)
Определения groupaction.php:420
setGridType(string $value)
Определения groupaction.php:205
actionElementUnlockPanel(array $params=[])
Определения groupaction.php:700
const SECTION_CHOOSER_SELECT
Определения iblocktable.php:97
const SECTION_CHOOSER_PATH
Определения iblocktable.php:99
const RESET_CONTROLS
Определения actions.php:24
const CREATE
Определения actions.php:14
const BUTTON
Определения types.php:16
const TEXT
Определения types.php:15
const DROPDOWN
Определения types.php:13
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
$data['IS_AVAILABLE']
Определения .description.php:13
</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(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList
Определения options.php:2065
$method
Определения index.php:27
$action
Определения file_dialog.php:21
$iterator
Определения yandex_run.php:610