Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
scripttemplateprovider.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Integration\UI\EntitySelector
;
4
5
use
Bitrix\Bizproc\Workflow\Template\Tpl
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\ORM\Query\Filter\ConditionTree
;
8
use
Bitrix\UI\EntitySelector\Dialog
;
9
use
Bitrix\UI\EntitySelector\Tab
;
10
11
class
ScriptTemplateProvider
extends
TemplateProvider
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
102
protected
function
getDefaultTemplateFilter
():
ConditionTree
103
{
104
return
(
105
\
Bitrix
\Main\ORM\
Query
\Query::filter()
106
->where(
'ACTIVE'
,
'Y'
)
107
->where(
'AUTO_EXECUTE'
, \CBPDocumentEventType::Script)
108
);
109
}
110
}
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider
Definition
scripttemplateprovider.php:12
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\__construct
__construct(array $options=[])
Definition
scripttemplateprovider.php:16
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\ENTITY_ID
const ENTITY_ID
Definition
scripttemplateprovider.php:13
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\fillDialog
fillDialog(Dialog $dialog)
Definition
scripttemplateprovider.php:22
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\getDefaultTemplateFilter
getDefaultTemplateFilter()
Definition
scripttemplateprovider.php:102
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\TAB_ID
const TAB_ID
Definition
scripttemplateprovider.php:14
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\canUserStartWorkflow
canUserStartWorkflow(int $userId, array $complexDocumentType)
Definition
scripttemplateprovider.php:88
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\openTemplateTree
openTemplateTree(Dialog $dialog, Tpl $template)
Definition
scripttemplateprovider.php:61
Bitrix\Bizproc\Integration\UI\EntitySelector\ScriptTemplateProvider\addTemplatesTab
addTemplatesTab(Dialog $dialog)
Definition
scripttemplateprovider.php:51
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider
Definition
templateprovider.php:18
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\getComplexDocumentTypes
getComplexDocumentTypes(string $moduleId='')
Definition
templateprovider.php:315
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\isUserWorkflowTemplateAdmin
isUserWorkflowTemplateAdmin(int $userId)
Definition
templateprovider.php:425
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\openPreselectedItemTree
openPreselectedItemTree(Dialog $dialog)
Definition
templateprovider.php:112
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\fillDocumentItem
fillDocumentItem(Dialog $dialog, Item $documentItem, int $currentUserId)
Definition
templateprovider.php:257
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\getDocumentItem
getDocumentItem(Dialog $dialog, array $complexDocumentType)
Definition
templateprovider.php:192
Bitrix\Bizproc\Integration\UI\EntitySelector\TemplateProvider\getCurrentUserId
getCurrentUserId()
Definition
templateprovider.php:430
Bitrix\Bizproc\Workflow\Template\Tpl
Definition
tpl.php:8
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Query\Filter\ConditionTree
Definition
conditiontree.php:28
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\UI\EntitySelector\BaseProvider\$options
$options
Definition
baseprovider.php:6
Bitrix\UI\EntitySelector\Dialog
Definition
dialog.php:10
Bitrix\UI\EntitySelector\Dialog\addItem
addItem(Item $item)
Definition
dialog.php:112
Bitrix\UI\EntitySelector\Dialog\addTab
addTab(Tab $tab)
Definition
dialog.php:235
Bitrix\UI\EntitySelector\Dialog\getItemCollection
getItemCollection()
Definition
dialog.php:102
Bitrix\UI\EntitySelector\Tab
Definition
tab.php:5
Bitrix\Bizproc\Integration\UI\EntitySelector
Definition
automationtemplateprovider.php:3
Bitrix
modules
bizproc
lib
integration
ui
entityselector
scripttemplateprovider.php
Создано системой
1.10.0