5use Bitrix\Bizproc\Workflow\Template\Entity\EO_WorkflowTemplate_Collection;
7use Bitrix\Bizproc\WorkflowTemplateTable;
20 protected const TAB_ID =
'templates';
28 parent::__construct();
30 $this->options[
'showManual'] = (isset(
$options[
'showManual']) &&
$options[
'showManual'] ===
true);
40 $ids = array_filter(array_map(
'intval', $ids));
41 $templates = $this->getTemplatesByIds($ids);
45 foreach ($templates as $template)
49 $items[] = $this->makeItem([
'id' => $template->getId(),
'title' => $template->getName()],
false);
62 foreach ($complexDocumentTypes as $documentType)
64 $moduleId = $documentType[0];
70 $moduleItem->setNodeOptions([
'dynamic' =>
true,
'open' =>
false]);
82 'data:image/svg+xml,%3Csvg width=%2224%22 height=%2224%22 viewBox=%220 0 24 24%22 fill=%22none%22'
83 .
' xmlns=%22http://www.w3.org/2000/svg%22%3E%3Cpath'
84 .
' d=%22M5.89991 7.87642C5.89991 6.8374 6.7422 5.99512 7.78121 5.99512H16.2483C17.2873 5.99512 18.1296'
85 .
' 6.8374 18.1296 7.87642V9.7578H19.6965C19.8641 9.7578 19.948 9.96044 19.8295 10.079L17.1106'
86 .
' 12.7978C17.0372 12.8713 16.9181 12.8713 16.8446 12.7978L14.1257 10.079C14.0072 9.96044 14.0912 9.7578'
87 .
' 14.2588 9.7578H15.8878V8.63549C15.8878 8.39305 15.6913 8.19651 15.4489 8.19651H8.58066C8.33822 8.19651'
88 .
' 8.14169 8.39305 8.14169 8.63549V9.51372L5.89991 9.26298V7.87642Z%22'
89 .
' fill=%22%23525C69%22/%3E%3Cpath d=%22M5.89991 14.2046V16.1233C5.89991 17.1623 6.7422 18.0046 7.78121'
90 .
' 18.0046H16.2483C17.2873 18.0046 18.1296 17.1623 18.1296 16.1233V14.6184L15.8878'
91 .
' 14.3677V15.3642C15.8878 15.6067 15.6913 15.8032 15.4489 15.8032H8.58066C8.33822 15.8032 8.14169 15.6067'
92 .
' 8.14169 15.3642V14.2046H9.7412C9.9088 14.2046 9.99274 14.002 9.87423 13.8835L7.15538 11.1646C7.08191'
93 .
' 11.0911 6.96279 11.0911 6.88932 11.1646L4.17047 13.8835C4.05195 14.002 4.13589 14.2046 4.3035'
94 .
' 14.2046H5.89991Z%22 fill=%22%23525C69%22/%3E%3C/svg%3E%0A'
98 'id' => static::TAB_ID,
99 'title' =>
Loc::getMessage(
'BIZPROC_ENTITY_SELECTOR_TEMPLATES_TAB_TEMPLATES_TITLE'),
100 'itemOrder' => [
'sort' =>
'asc nulls last'],
103 'title' =>
Loc::getMessage(
'BIZPROC_ENTITY_SELECTOR_TEMPLATES_TAB_STUB_TITLE'),
107 'selected' => str_replace(
'525C69',
'fff', $icon),
117 $ids = array_keys($preselectedItems);
118 $templates = $this->getTemplatesByIds(array_filter(array_map(
'intval', $ids)));
120 foreach ($templates as $template)
123 IsModuleInstalled($template->getModuleId())
124 && $this->canUserStartWorkflow($currentUserId, $template->getDocumentComplexType())
143 ->setNodeOptions([
'open' =>
true,
'dynamic' =>
false,
'itemOrder' => [
'sort' =>
'asc nulls last']])
147 $documentItem = $moduleItem->getChildren()->get(
149 $this->
createDocumentId($template->getModuleId(), $template->getDocumentType())
154 $documentItem = $moduleItem->getChildren()->get(
156 $this->
createDocumentId($template->getModuleId(), $template->getDocumentType())
160 ->setNodeOptions([
'open' =>
true,
'dynamic' =>
false,
'itemOrder' => [
'sort' =>
'asc nulls last']])
164 $templateItem = $documentItem->getChildren()->get(static::ENTITY_ID, $template->getId());
168 $templateItem = $documentItem->getChildren()->get(static::ENTITY_ID, $template->getId());
170 $templateItem->setSort(1);
178 if ($moduleItem ===
null)
181 Loc::getMessage(
'BIZPROC_ENTITY_SELECTOR_TEMPLATES_MODULE_' . mb_strtoupper($moduleId))
184 $moduleItem = $this->makeItem([
'id' => $id,
'title' => $title]);
185 $moduleItem->setCustomData([
'moduleId' => $moduleId]);
186 $moduleItem->setSearchable(
false);
194 $id = $this->
createDocumentId($complexDocumentType[0], $complexDocumentType[2]);
196 if ($documentItem ===
null)
198 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
200 $title = $documentService->getDocumentTypeCaption($complexDocumentType);
201 if (\CBPHelper::isEmptyValue($title))
203 $title = $complexDocumentType[2];
206 $documentItem = $this->makeItem([
'id' => $id,
'title' => $title]);
207 $documentItem->setCustomData([
208 'moduleId' => $complexDocumentType[0],
209 'documentType' => $complexDocumentType[2],
211 $documentItem->setSearchable(
false);
214 return $documentItem;
220 $parentItemId = $parentItem->
getId();
222 if (mb_strpos($parentItemId, static::ITEM_MODULE_ID_PREFIX) === 0)
224 if (mb_strpos($parentItemId, static::ITEM_DOCUMENT_TYPE_PREFIX) !==
false)
236 parent::getChildren($parentItem, $dialog);
242 if ($moduleId && IsModuleInstalled($moduleId))
245 foreach ($complexDocumentTypes as $complexDocumentType)
250 $documentItem->setNodeOptions([
'dynamic' =>
true]);
251 $moduleItem->
addChild($documentItem);
261 if ($moduleId && $documentType && IsModuleInstalled($moduleId))
263 $templates = $this->getTemplatesByDocumentType($moduleId, $documentType);
264 foreach ($templates as $template)
268 $item = $this->makeItem([
'id' => $template->getId(),
'title' => $template->getName()]);
275 private function getTemplatesByIds(array $ids): EO_WorkflowTemplate_Collection
279 return new EO_WorkflowTemplate_Collection();
283 WorkflowTemplateTable::query()
284 ->setSelect([
'ID',
'MODULE_ID',
'ENTITY',
'DOCUMENT_TYPE',
'NAME'])
287 if (count($ids) === 1)
289 $query->where(
'ID', $ids[0]);
293 $query->whereIn(
'ID', $ids);
296 return $query->exec()->fetchCollection();
299 private function getTemplatesByDocumentType(
302 ): \
Bitrix\Bizproc\Workflow\Template\Entity\EO_WorkflowTemplate_Collection
305 WorkflowTemplateTable::query()
306 ->setSelect([
'ID',
'MODULE_ID',
'ENTITY',
'DOCUMENT_TYPE',
'NAME'])
307 ->where(
'MODULE_ID', $moduleId)
308 ->where(
'DOCUMENT_TYPE', $documentType)
312 return $query->exec()->fetchCollection();
317 if ($this->complexDocumentTypesCache ===
null)
320 WorkflowTemplateTable::query()
322 ->setSelect([
'MODULE_ID',
'ENTITY',
'DOCUMENT_TYPE'])
325 $complexDocumentTypes = $query->exec()->fetchAll();
327 $this->complexDocumentTypesCache = [];
328 foreach ($complexDocumentTypes as $documentType)
330 $this->complexDocumentTypesCache[] =
331 [$documentType[
'MODULE_ID'], $documentType[
'ENTITY'], $documentType[
'DOCUMENT_TYPE']]
336 $filter =
static fn ($docType) => ($docType[0] === $moduleId);
346 WorkflowTemplateTable::query()
347 ->setSelect([
'ID',
'MODULE_ID',
'ENTITY',
'DOCUMENT_TYPE',
'NAME'])
348 ->whereLike(
'NAME',
"%{$searchQuery->getQuery()}%")
354 foreach ($templates as $template)
358 $items[] = $this->makeItem([
'id' => $template->getId(),
'title' => $template->getName()],
false);
370 $filter = \Bitrix\Main\ORM\Query\Query::filter();
371 $filter->where(
'ACTIVE',
'Y');
374 \Bitrix\Main\ORM\Query\Query::filter()
375 ->logic(ConditionTree::LOGIC_OR)
376 ->where(
'AUTO_EXECUTE',
'<', \CBPDocumentEventType::Automation)
379 if ($this->options[
'showManual'])
381 $autoExecuteFilter->where(
'AUTO_EXECUTE', \CBPDocumentEventType::Manual);
384 return $filter->where($autoExecuteFilter);
396 return \CBPDocument::canUserOperateDocumentType(
397 \CBPCanUserOperateOperation::StartWorkflow,
402 catch (\CBPArgumentNullException $exception)
410 private function makeItem(array $data,
bool $addTab =
true):
Item
414 'entityId' => static::ENTITY_ID,
415 'title' => $data[
'title'],
419 $item->addTab(static::TAB_ID);
427 return (
new \CBPWorkflowTemplateUser($userId))->isAdmin();
432 return (
int)(CurrentUser::get()->getId());
437 return static::ITEM_MODULE_ID_PREFIX . $moduleId;
442 return $this->
createModuleId($moduleId) .
'@' . static::ITEM_DOCUMENT_TYPE_PREFIX . $documentId;
447 return mb_substr($id, strlen(static::ITEM_MODULE_ID_PREFIX));
452 [$moduleItemId, $documentItemId] = mb_split(
'@', $id);
454 $document = mb_substr($documentItemId, strlen(static::ITEM_DOCUMENT_TYPE_PREFIX));
getComplexDocumentTypes(string $moduleId='')
getChildren(Item $parentItem, Dialog $dialog)
__construct(array $options=[])
parseDocumentItemId(string $id)
isUserWorkflowTemplateAdmin(int $userId)
openPreselectedItemTree(Dialog $dialog)
fillDialog(Dialog $dialog)
getModuleItem(Dialog $dialog, string $moduleId)
fillDocumentItem(Dialog $dialog, Item $documentItem, int $currentUserId)
getDefaultTemplateFilter()
fillModuleItem(Dialog $dialog, Item $moduleItem, int $currentUserId)
getDocumentItem(Dialog $dialog, array $complexDocumentType)
const ITEM_MODULE_ID_PREFIX
array $complexDocumentTypesCache
createDocumentId(string $moduleId, string $documentId)
const ITEM_DOCUMENT_TYPE_PREFIX
canUserStartWorkflow(int $userId, array $complexDocumentType)
openTemplateTree(Dialog $dialog, Tpl $template)
doSearch(SearchQuery $searchQuery, Dialog $dialog)
addTemplatesTab(Dialog $dialog)
parseModuleItemId(string $id)
createModuleId(string $moduleId)
static getMessage($code, $replace=null, $language=null)
getPreselectedCollection()