Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
scripttemplateprovider.php
1<?php
2
4
10
12{
13 protected const ENTITY_ID = 'bizproc-script-template';
14 protected const TAB_ID = 'script-templates';
15
16 public function __construct(array $options = [])
17 {
18 parent::__construct($options);
19 $this->options = [];
20 }
21
22 public function fillDialog(Dialog $dialog): void
23 {
24 $this->addTemplatesTab($dialog);
25 $currentUserId = $this->getCurrentUserId();
26
27 $complexDocumentTypes = $this->getComplexDocumentTypes();
28 foreach ($complexDocumentTypes as $documentType)
29 {
30 $moduleId = $documentType[0];
31 if (IsModuleInstalled($moduleId) && $this->canUserStartWorkflow($currentUserId, $documentType))
32 {
33 $documentItem = $this->getDocumentItem($dialog, $documentType);
34 if (!$dialog->getItemCollection()->has($documentItem))
35 {
36 $documentItem->setNodeOptions(['dynamic' => true, 'open' => false]);
37 $dialog->addItem($documentItem);
38 }
39 }
40 }
41
42 if (count($dialog->getItemCollection()->getEntityItems(static::ENTITY_ID)) === 1)
43 {
44 $first = current($dialog->getItemCollection()->getEntityItems(static::ENTITY_ID));
45 $first->setNodeOptions(['dynamic' => true, 'open' => true]);
46 }
47
48 $this->openPreselectedItemTree($dialog);
49 }
50
51 protected function addTemplatesTab(Dialog $dialog): void
52 {
53 $dialog->addTab(new Tab([
54 'id' => self::TAB_ID,
55 'title' => Loc::getMessage('BIZPROC_ENTITY_SELECTOR_TEMPLATES_TAB_SCRIPT_TEMPLATES_TITLE'),
56 'itemOrder' => ['sort' => 'asc nulls last'],
57 'stub' => true,
58 ]));
59 }
60
61 protected function openTemplateTree(Dialog $dialog, Tpl $template): void
62 {
63 $currentUserId = $this->getCurrentUserId();
64
65 $documentItem = $dialog->getItemCollection()->get(
66 static::ENTITY_ID,
67 static::ITEM_DOCUMENT_TYPE_PREFIX . $template->getDocumentType()
68 );
69
70 if ($documentItem)
71 {
72 $documentItem
73 ->setNodeOptions(['open' => true, 'dynamic' => false, 'itemOrder' => ['sort' => 'asc nulls last']])
74 ->setSort(1)
75 ;
76
77 $templateItem = $documentItem->getChildren()->get(static::ENTITY_ID, $template->getId());
78 if (!$templateItem)
79 {
80 $this->fillDocumentItem($dialog, $documentItem, $currentUserId);
81 $templateItem = $documentItem->getChildren()->get(self::ENTITY_ID, $template->getId());
82 }
83
84 $templateItem->setSort(1);
85 }
86 }
87
88 protected function canUserStartWorkflow(int $userId, array $complexDocumentType): bool
89 {
90 // todo: use API \Bitrix\Bizproc\Script\Manager
91
92 return (
93 $this->isUserWorkflowTemplateAdmin($userId)
94 || \CBPDocument::canUserOperateDocumentType(
95 \CBPCanUserOperateOperation::ViewWorkflow,
96 $userId,
97 $complexDocumentType
98 )
99 );
100 }
101
103 {
104 return (
105 \Bitrix\Main\ORM\Query\Query::filter()
106 ->where('ACTIVE', 'Y')
107 ->where('AUTO_EXECUTE', \CBPDocumentEventType::Script)
108 );
109 }
110}
fillDocumentItem(Dialog $dialog, Item $documentItem, int $currentUserId)
getDocumentItem(Dialog $dialog, array $complexDocumentType)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29