Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
robot.php
1
<?php
2
3
namespace
Bitrix\Bizproc\Automation\Engine
;
4
5
use
Bitrix\Bizproc\Workflow\Template\SourceType
;
6
7
class
Robot
8
{
10
protected
$bizprocActivity
;
12
protected
$delayInterval
;
13
protected
$delayName
;
15
protected
$condition
;
16
protected
$executeAfterPrevious
=
false
;
17
18
public
function
__construct
(array
$bizprocActivity
)
19
{
20
if
(isset(
$bizprocActivity
[
'Delay'
]))
21
{
22
$this->
setDelayInterval
(
new
DelayInterval
(
$bizprocActivity
[
'Delay'
]));
23
unset(
$bizprocActivity
[
'Delay'
]);
24
}
25
if
(isset(
$bizprocActivity
[
'DelayName'
]))
26
{
27
$this->
setDelayName
($bizprocActivity[
'DelayName'
]);
28
unset(
$bizprocActivity
[
'DelayName'
]);
29
}
30
if
(isset(
$bizprocActivity
[
'Condition'
]))
31
{
32
$this->
setCondition
(
new
ConditionGroup
(
$bizprocActivity
[
'Condition'
]));
33
unset(
$bizprocActivity
[
'Condition'
]);
34
}
35
36
if
(isset(
$bizprocActivity
[
'ExecuteAfterPrevious'
]) && (
int
)
$bizprocActivity
[
'ExecuteAfterPrevious'
] === 1)
37
{
38
$this->
setExecuteAfterPrevious
();
39
}
40
unset(
$bizprocActivity
[
'ExecuteAfterPrevious'
]);
41
42
$this->bizprocActivity =
$bizprocActivity
;
43
}
44
48
public
function
setDelayInterval
(
DelayInterval
$delayInterval
)
49
{
50
$this->delayInterval =
$delayInterval
;
51
}
52
56
public
function
getDelayInterval
()
57
{
58
return
$this->delayInterval
;
59
}
60
64
public
function
setCondition
(
ConditionGroup
$condition
)
65
{
66
$this->condition =
$condition
;
67
}
68
72
public
function
getCondition
()
73
{
74
return
$this->condition
;
75
}
76
80
public
function
setDelayName
(
$delayName
)
81
{
82
$this->delayName = (string)
$delayName
;
83
}
84
88
public
function
getDelayName
()
89
{
90
return
$this->delayName
;
91
}
92
93
public
function
setExecuteAfterPrevious
()
94
{
95
$this->executeAfterPrevious =
true
;
96
}
97
98
public
function
isExecuteAfterPrevious
()
99
{
100
return
$this->executeAfterPrevious
;
101
}
102
103
public
function
getProperties
()
104
{
105
return
isset($this->bizprocActivity[
'Properties'
]) && is_array($this->bizprocActivity[
'Properties'
])
106
? $this->bizprocActivity[
'Properties'
] : array();
107
}
108
109
public
function
setProperties
(array $properties): self
110
{
111
$this->bizprocActivity[
'Properties'
] = $properties;
112
return
$this;
113
}
114
115
public
function
getProperty
(
string
$name)
116
{
117
$properties = $this->
getProperties
();
118
return
array_key_exists($name, $properties) ? $properties[$name] :
null
;
119
}
120
121
public
function
setProperty
(
string
$name, $value)
122
{
123
$properties = $this->
getProperties
();
124
$properties[$name] = $value;
125
return
$this->
setProperties
($properties);
126
}
127
128
public
function
getReturnProperties
(): array
129
{
130
return \CBPRuntime::GetRuntime(
true
)->getActivityReturnProperties($this->
getType
());
131
}
132
133
public
function
getReturnProperty
(
string
$name): ?array
134
{
135
$props = $this->
getReturnProperties
();
136
return
($props && isset($props[$name])) ? $props[$name] :
null
;
137
}
138
139
public
function
getTitle
()
140
{
141
return
$this->
getProperty
(
'Title'
);
142
}
143
144
public
function
getName
()
145
{
146
return
$this->bizprocActivity[
'Name'
];
147
}
148
149
public
function
getType
()
150
{
151
return
$this->bizprocActivity[
'Type'
];
152
}
153
154
public
function
isActivated
(): bool
155
{
156
return \CBPHelper::getBool($this->bizprocActivity[
'Activated'
] ??
true
);
157
}
158
159
public
function
getDescription
(): ?array
160
{
161
return \CBPRuntime::GetRuntime(
true
)->GetActivityDescription($this->
getType
());
162
}
163
164
public
function
toArray
()
165
{
166
$activity =
$this->bizprocActivity
;
167
unset($activity[
'Children'
]);
//Robot activities has no Children
168
$delayInterval
= $this->
getDelayInterval
();
169
if
(
$delayInterval
)
170
{
171
$activity[
'Delay'
] =
$delayInterval
->toArray();
172
$activity[
'DelayName'
] = $this->
getDelayName
();
173
}
174
if
($this->
isExecuteAfterPrevious
())
175
$activity[
'ExecuteAfterPrevious'
] = 1;
176
177
$condition
= $this->
getCondition
();
178
if
(
$condition
)
179
{
180
$activity[
'Condition'
] =
$condition
->toArray();
181
}
182
183
return
$activity;
184
}
185
186
public
function
getBizprocActivity
()
187
{
188
$activity =
$this->bizprocActivity
;
189
$activity[
'Children'
] = array();
190
return
$activity;
191
}
192
193
public
static
function
generateName
()
194
{
195
return
'A'
.mt_rand(10000, 99999)
196
.
'_'
.mt_rand(10000, 99999)
197
.
'_'
.mt_rand(10000, 99999)
198
.
'_'
.mt_rand(10000, 99999);
199
}
200
201
public
function
collectUsages
(): array
202
{
203
\CBPActivity::IncludeActivityFile($this->
getType
());
204
try
205
{
206
$activity = \CBPActivity::createInstance($this->
getType
(), $this->
getName
());
207
if
($activity)
208
{
209
$activity->initializeFromArray($this->
getProperties
());
210
211
return
$activity->collectUsages();
212
}
213
}
214
catch
(\Exception $e)
215
{
216
}
217
218
return
[];
219
}
220
221
public
function
hasBrokenLink
(\
Bitrix
\Bizproc\Automation\Engine\
Template
$template): bool
222
{
223
$usages = $this->
collectUsages
();
224
if
(!$usages)
225
{
226
return
false
;
227
}
228
229
$checkObjects = [
230
\
Bitrix\Bizproc\Workflow\Template\SourceType::DocumentField
,
231
\
Bitrix\Bizproc\Workflow\Template\SourceType::GlobalConstant
,
232
\
Bitrix\Bizproc\Workflow\Template\SourceType::GlobalVariable
,
233
\
Bitrix\Bizproc\Workflow\Template\SourceType::Variable
,
234
\
Bitrix\Bizproc\Workflow\Template\SourceType::Constant
,
235
];
236
237
foreach
($usages as $usage)
238
{
239
$object = $usage[0];
240
$field = $usage[1];
241
242
if
(in_array($object, $checkObjects))
243
{
244
$property = $template->getProperty($object, $field);
245
246
if
(!$property)
247
{
248
return
true
;
249
}
250
}
251
}
252
253
return
false
;
254
}
255
}
Bitrix\Bizproc\Automation\Engine\ConditionGroup
Definition
conditiongroup.php:13
Bitrix\Bizproc\Automation\Engine\DelayInterval
Definition
delayinterval.php:7
Bitrix\Bizproc\Automation\Engine\Robot
Definition
robot.php:8
Bitrix\Bizproc\Automation\Engine\Robot\setDelayInterval
setDelayInterval(DelayInterval $delayInterval)
Definition
robot.php:48
Bitrix\Bizproc\Automation\Engine\Robot\$condition
$condition
Definition
robot.php:15
Bitrix\Bizproc\Automation\Engine\Robot\isExecuteAfterPrevious
isExecuteAfterPrevious()
Definition
robot.php:98
Bitrix\Bizproc\Automation\Engine\Robot\getProperty
getProperty(string $name)
Definition
robot.php:115
Bitrix\Bizproc\Automation\Engine\Robot\setDelayName
setDelayName($delayName)
Definition
robot.php:80
Bitrix\Bizproc\Automation\Engine\Robot\isActivated
isActivated()
Definition
robot.php:154
Bitrix\Bizproc\Automation\Engine\Robot\getDescription
getDescription()
Definition
robot.php:159
Bitrix\Bizproc\Automation\Engine\Robot\getCondition
getCondition()
Definition
robot.php:72
Bitrix\Bizproc\Automation\Engine\Robot\getName
getName()
Definition
robot.php:144
Bitrix\Bizproc\Automation\Engine\Robot\generateName
static generateName()
Definition
robot.php:193
Bitrix\Bizproc\Automation\Engine\Robot\$delayInterval
$delayInterval
Definition
robot.php:12
Bitrix\Bizproc\Automation\Engine\Robot\setProperties
setProperties(array $properties)
Definition
robot.php:109
Bitrix\Bizproc\Automation\Engine\Robot\toArray
toArray()
Definition
robot.php:164
Bitrix\Bizproc\Automation\Engine\Robot\$executeAfterPrevious
$executeAfterPrevious
Definition
robot.php:16
Bitrix\Bizproc\Automation\Engine\Robot\getType
getType()
Definition
robot.php:149
Bitrix\Bizproc\Automation\Engine\Robot\getDelayName
getDelayName()
Definition
robot.php:88
Bitrix\Bizproc\Automation\Engine\Robot\setCondition
setCondition(ConditionGroup $condition)
Definition
robot.php:64
Bitrix\Bizproc\Automation\Engine\Robot\getDelayInterval
getDelayInterval()
Definition
robot.php:56
Bitrix\Bizproc\Automation\Engine\Robot\getTitle
getTitle()
Definition
robot.php:139
Bitrix\Bizproc\Automation\Engine\Robot\hasBrokenLink
hasBrokenLink(\Bitrix\Bizproc\Automation\Engine\Template $template)
Definition
robot.php:221
Bitrix\Bizproc\Automation\Engine\Robot\getReturnProperty
getReturnProperty(string $name)
Definition
robot.php:133
Bitrix\Bizproc\Automation\Engine\Robot\getProperties
getProperties()
Definition
robot.php:103
Bitrix\Bizproc\Automation\Engine\Robot\setProperty
setProperty(string $name, $value)
Definition
robot.php:121
Bitrix\Bizproc\Automation\Engine\Robot\getReturnProperties
getReturnProperties()
Definition
robot.php:128
Bitrix\Bizproc\Automation\Engine\Robot\collectUsages
collectUsages()
Definition
robot.php:201
Bitrix\Bizproc\Automation\Engine\Robot\$bizprocActivity
$bizprocActivity
Definition
robot.php:10
Bitrix\Bizproc\Automation\Engine\Robot\__construct
__construct(array $bizprocActivity)
Definition
robot.php:18
Bitrix\Bizproc\Automation\Engine\Robot\setExecuteAfterPrevious
setExecuteAfterPrevious()
Definition
robot.php:93
Bitrix\Bizproc\Automation\Engine\Robot\$delayName
$delayName
Definition
robot.php:13
Bitrix\Bizproc\Automation\Engine\Robot\getBizprocActivity
getBizprocActivity()
Definition
robot.php:186
Bitrix\Bizproc\Automation\Engine\Template
Definition
template.php:22
Bitrix\Bizproc\Workflow\Template\SourceType
Definition
sourcetype.php:6
Bitrix\Bizproc\Workflow\Template\SourceType\Constant
const Constant
Definition
sourcetype.php:10
Bitrix\Bizproc\Workflow\Template\SourceType\DocumentField
const DocumentField
Definition
sourcetype.php:7
Bitrix\Bizproc\Workflow\Template\SourceType\GlobalConstant
const GlobalConstant
Definition
sourcetype.php:11
Bitrix\Bizproc\Workflow\Template\SourceType\GlobalVariable
const GlobalVariable
Definition
sourcetype.php:12
Bitrix\Bizproc\Workflow\Template\SourceType\Variable
const Variable
Definition
sourcetype.php:9
Bitrix\Bizproc\Automation\Engine
Definition
condition.php:2
Bitrix
modules
bizproc
lib
automation
engine
robot.php
Создано системой
1.10.0