1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
basetarget.php
См. документацию.
1
<?php
2
namespace
Bitrix\Bizproc\Automation\Target
;
3
4
use
Bitrix\Bizproc\Automation\Engine\ConditionGroup
;
5
use Bitrix\Bizproc\Automation\Engine\Runtime;
6
use
Bitrix\Bizproc\Automation\Engine\TemplatesScheme
;
7
use
Bitrix\Bizproc\Automation\Trigger\Entity\EO_Trigger
;
8
use
Bitrix\Bizproc\Automation\Trigger\Entity\TriggerTable
;
9
10
abstract
class
BaseTarget
11
{
12
private
const
CACHE_TTL = 7200;
13
14
protected
$runtime
;
15
protected
$appliedTrigger
;
16
protected
$documentId
;
17
protected
$documentType
;
18
protected
array
$appliedTriggerConditionResults
= [];
19
20
public
function
isAvailable
()
21
{
22
return
true
;
23
}
24
30
public
function
setAppliedTrigger
(
array
$trigger)
31
{
32
$this->appliedTrigger = $trigger;
33
34
return
$this;
35
}
36
41
public
function
getAppliedTrigger
()
42
{
43
return
$this->appliedTrigger
;
44
}
45
49
public
function
getRuntime
()
50
{
51
if
($this->runtime ===
null
)
52
{
53
$this->runtime =
new
Runtime();
54
$this->runtime->setTarget($this);
55
}
56
57
return
$this->runtime
;
58
}
59
60
abstract
public
function
getDocumentStatus
();
61
62
public
function
getDocumentCategory
(): int
63
{
64
return
0;
65
}
66
67
abstract
public
function
setDocumentStatus
($statusId);
68
69
abstract
public
function
getDocumentStatusList
($categoryId = 0);
70
71
public
function
getTriggers
(
array
$statuses)
72
{
73
$result
= [];
74
$documentType
= $this->
getDocumentType
();
75
76
$iterator
= TriggerTable::getList(
array
(
77
'filter'
=>
array
(
78
'=MODULE_ID'
=>
$documentType
[0],
79
'=ENTITY'
=>
$documentType
[1],
80
'=DOCUMENT_TYPE'
=>
$documentType
[2],
81
'@DOCUMENT_STATUS'
=> $statuses
82
),
83
'cache'
=> [
84
'ttl'
=> self::CACHE_TTL
85
]
86
));
87
88
while
($row =
$iterator
->fetch())
89
{
90
$row[
'DOCUMENT_TYPE'
] =
$documentType
;
91
$result
[] = $row;
92
}
93
94
return
$result
;
95
}
96
101
public
function
getTriggerObjects
(
array
$statuses):
array
102
{
103
$documentType
= $this->
getDocumentType
();
104
105
$iterator
= TriggerTable::getList([
106
'filter'
=> [
107
'=MODULE_ID'
=>
$documentType
[0],
108
'=ENTITY'
=>
$documentType
[1],
109
'=DOCUMENT_TYPE'
=>
$documentType
[2],
110
'@DOCUMENT_STATUS'
=> $statuses,
111
],
112
]);
113
114
return
$iterator
->fetchCollection()->getAll();
115
}
116
117
public
function
prepareTriggersToSave
(
array
&$triggers)
118
{
119
foreach
($triggers as
$i
=> $trigger)
120
{
121
if
(isset($trigger[
'DELETED'
]) && $trigger[
'DELETED'
] ===
'Y'
)
122
{
123
continue
;
124
}
125
126
$triggers[
$i
][
'APPLY_RULES'
] = $this->prepareApplyRules($trigger[
'APPLY_RULES'
]);
127
}
128
}
129
130
public
function
prepareTriggersToShow
(
array
&$triggers)
131
{
132
foreach
($triggers as
$i
=> $trigger)
133
{
134
$triggers[
$i
][
'APPLY_RULES'
] = $this->prepareApplyRules($trigger[
'APPLY_RULES'
],
true
);
135
}
136
}
137
138
public
function
setTriggers
(
array
$triggers)
139
{
140
$updatedTriggers = [];
141
foreach
($triggers as $trigger)
142
{
143
$triggerId = isset($trigger[
'ID'
]) ? (int)$trigger[
'ID'
] : 0;
144
145
if
(isset($trigger[
'DELETED'
]) && $trigger[
'DELETED'
] ===
'Y'
)
146
{
147
if
($triggerId > 0)
148
{
149
//TODO: check document type
150
TriggerTable::delete($triggerId);
151
}
152
continue
;
153
}
154
155
if
($triggerId > 0)
156
{
157
TriggerTable::update($triggerId,
array
(
158
'NAME'
=> $trigger[
'NAME'
],
159
'DOCUMENT_STATUS'
=> $trigger[
'DOCUMENT_STATUS'
],
160
'APPLY_RULES'
=> is_array($trigger[
'APPLY_RULES'
]) ? $trigger[
'APPLY_RULES'
] :
null
161
));
162
}
163
elseif
(isset($trigger[
'CODE'
]) && isset($trigger[
'DOCUMENT_STATUS'
]))
164
{
165
$documentType
= $this->
getDocumentType
();
166
$addResult = TriggerTable::add(
array
(
167
'NAME'
=> $trigger[
'NAME'
],
168
'MODULE_ID'
=>
$documentType
[0],
169
'ENTITY'
=>
$documentType
[1],
170
'DOCUMENT_TYPE'
=>
$documentType
[2],
171
'DOCUMENT_STATUS'
=> $trigger[
'DOCUMENT_STATUS'
],
172
'CODE'
=> $trigger[
'CODE'
],
173
'APPLY_RULES'
=> is_array($trigger[
'APPLY_RULES'
]) ? $trigger[
'APPLY_RULES'
] :
null
174
));
175
176
if
($addResult->isSuccess())
177
{
178
$trigger[
'ID'
] = $addResult->getId();
179
}
180
}
181
$updatedTriggers[] = $trigger;
182
}
183
184
return
$updatedTriggers;
185
}
186
187
public
function
extractTemplateParameters
(
array
$triggers):
array
188
{
189
$params
= [];
190
foreach
($triggers as $trigger)
191
{
192
$triggerDescription = $this->
getAvailableTriggerByCode
($trigger[
'CODE'
]);
193
$status
= $trigger[
'DOCUMENT_STATUS'
];
194
195
if
($triggerDescription && isset($triggerDescription[
'RETURN'
]))
196
{
197
if
(!isset(
$params
[
$status
]))
198
{
199
$params
[
$status
] = [];
200
}
201
foreach
($triggerDescription[
'RETURN'
] as $property)
202
{
203
$params
[
$status
][$property[
'Id'
]] = $property;
204
}
205
}
206
}
207
return
$params
;
208
}
209
210
private
function
prepareApplyRules($rules, $external =
false
): ?
array
211
{
212
if
(!is_array($rules))
213
{
214
return
null
;
215
}
216
217
if
(isset($rules[
'Condition'
]))
218
{
219
$condition =
new
ConditionGroup($rules[
'Condition'
]);
220
if
($external)
221
{
222
$condition->externalizeValues($this->
getDocumentType
());
223
}
224
else
225
{
226
$condition->internalizeValues($this->
getDocumentType
());
227
}
228
$rules[
'Condition'
] = $condition->toArray();
229
}
230
231
if
(isset($rules[
'ExecuteBy'
]))
232
{
233
if
($external)
234
{
235
$rules[
'ExecuteBy'
] = \CBPHelper::UsersArrayToString(
236
$rules[
'ExecuteBy'
],
237
null
,
238
$this->
getDocumentType
()
239
);
240
}
241
else
242
{
243
$rules[
'ExecuteBy'
] = \CBPHelper::UsersStringToArray(
244
$rules[
'ExecuteBy'
],
245
$this->
getDocumentType
(),
246
$errors
247
);
248
}
249
}
250
251
return
$rules;
252
}
253
257
public
function
getAvailableTriggers
()
258
{
259
return
[];
260
}
261
262
public
function
canTriggerSetExecuteBy
(): bool
263
{
264
return
false
;
265
}
266
271
public
function
getAvailableTriggerByCode
(
$code
): ?
array
272
{
273
foreach
($this->
getAvailableTriggers
() as $availableTrigger)
274
{
275
if
(
$code
=== $availableTrigger[
'CODE'
])
276
{
277
return
$availableTrigger;
278
}
279
}
280
return
null
;
281
}
282
283
public
function
setDocumentType
(
array
$documentType
)
284
{
285
return
$this->documentType =
$documentType
;
286
}
287
288
public
function
getDocumentType
()
289
{
290
return
$this->documentType
;
291
}
292
293
public
function
getDocumentId
()
294
{
295
return
$this->documentId
;
296
}
297
298
public
function
setDocumentId
(
$documentId
)
299
{
300
$this->documentId =
$documentId
;
301
return
$this;
302
}
303
304
public
function
getComplexDocumentId
():
array
305
{
306
$type
= $this->
getDocumentType
();
307
308
return
[
$type
[0],
$type
[1], $this->
getDocumentId
()];
309
}
310
311
public
function
getTemplatesScheme
(): ?
TemplatesScheme
312
{
313
return
null
;
314
}
315
316
public
function
setAppliedTriggerConditionResults
(
array
$log)
317
{
318
$this->appliedTriggerConditionResults = $log;
319
}
320
321
public
function
getAppliedTriggerConditionResults
():
array
322
{
323
return
$this->appliedTriggerConditionResults
;
324
}
325
326
public
function
getDocumentCategoryCode
(): string
327
{
328
return
''
;
329
}
330
}
$type
$type
Определения
options.php:106
Bitrix\Bizproc\Automation\Engine\ConditionGroup
Определения
conditiongroup.php:13
Bitrix\Bizproc\Automation\Engine\TemplatesScheme
Определения
templatesscheme.php:10
Bitrix\Bizproc\Automation\Target\BaseTarget
Определения
basetarget.php:11
Bitrix\Bizproc\Automation\Target\BaseTarget\setAppliedTrigger
setAppliedTrigger(array $trigger)
Определения
basetarget.php:30
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentCategory
getDocumentCategory()
Определения
basetarget.php:62
Bitrix\Bizproc\Automation\Target\BaseTarget\prepareTriggersToShow
prepareTriggersToShow(array &$triggers)
Определения
basetarget.php:130
Bitrix\Bizproc\Automation\Target\BaseTarget\setDocumentStatus
setDocumentStatus($statusId)
Bitrix\Bizproc\Automation\Target\BaseTarget\setAppliedTriggerConditionResults
setAppliedTriggerConditionResults(array $log)
Определения
basetarget.php:316
Bitrix\Bizproc\Automation\Target\BaseTarget\setTriggers
setTriggers(array $triggers)
Определения
basetarget.php:138
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentId
getDocumentId()
Определения
basetarget.php:293
Bitrix\Bizproc\Automation\Target\BaseTarget\setDocumentType
setDocumentType(array $documentType)
Определения
basetarget.php:283
Bitrix\Bizproc\Automation\Target\BaseTarget\getAppliedTriggerConditionResults
getAppliedTriggerConditionResults()
Определения
basetarget.php:321
Bitrix\Bizproc\Automation\Target\BaseTarget\getTemplatesScheme
getTemplatesScheme()
Определения
basetarget.php:311
Bitrix\Bizproc\Automation\Target\BaseTarget\prepareTriggersToSave
prepareTriggersToSave(array &$triggers)
Определения
basetarget.php:117
Bitrix\Bizproc\Automation\Target\BaseTarget\getTriggers
getTriggers(array $statuses)
Определения
basetarget.php:71
Bitrix\Bizproc\Automation\Target\BaseTarget\$documentType
$documentType
Определения
basetarget.php:17
Bitrix\Bizproc\Automation\Target\BaseTarget\extractTemplateParameters
extractTemplateParameters(array $triggers)
Определения
basetarget.php:187
Bitrix\Bizproc\Automation\Target\BaseTarget\canTriggerSetExecuteBy
canTriggerSetExecuteBy()
Определения
basetarget.php:262
Bitrix\Bizproc\Automation\Target\BaseTarget\$appliedTrigger
$appliedTrigger
Определения
basetarget.php:15
Bitrix\Bizproc\Automation\Target\BaseTarget\setDocumentId
setDocumentId($documentId)
Определения
basetarget.php:298
Bitrix\Bizproc\Automation\Target\BaseTarget\$runtime
$runtime
Определения
basetarget.php:14
Bitrix\Bizproc\Automation\Target\BaseTarget\getAvailableTriggerByCode
getAvailableTriggerByCode($code)
Определения
basetarget.php:271
Bitrix\Bizproc\Automation\Target\BaseTarget\getAppliedTrigger
getAppliedTrigger()
Определения
basetarget.php:41
Bitrix\Bizproc\Automation\Target\BaseTarget\getComplexDocumentId
getComplexDocumentId()
Определения
basetarget.php:304
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentStatus
getDocumentStatus()
Bitrix\Bizproc\Automation\Target\BaseTarget\getRuntime
getRuntime()
Определения
basetarget.php:49
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentType
getDocumentType()
Определения
basetarget.php:288
Bitrix\Bizproc\Automation\Target\BaseTarget\$documentId
$documentId
Определения
basetarget.php:16
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentStatusList
getDocumentStatusList($categoryId=0)
Bitrix\Bizproc\Automation\Target\BaseTarget\$appliedTriggerConditionResults
array $appliedTriggerConditionResults
Определения
basetarget.php:18
Bitrix\Bizproc\Automation\Target\BaseTarget\getTriggerObjects
getTriggerObjects(array $statuses)
Определения
basetarget.php:101
Bitrix\Bizproc\Automation\Target\BaseTarget\getAvailableTriggers
getAvailableTriggers()
Определения
basetarget.php:257
Bitrix\Bizproc\Automation\Target\BaseTarget\getDocumentCategoryCode
getDocumentCategoryCode()
Определения
basetarget.php:326
Bitrix\Bizproc\Automation\Target\BaseTarget\isAvailable
isAvailable()
Определения
basetarget.php:20
Bitrix\Bizproc\Automation\Trigger\Entity\EO_Trigger
Определения
orm.php:5931
Bitrix\Bizproc\Automation\Trigger\Entity\TriggerTable
Определения
trigger.php:23
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$errors
$errors
Определения
iblock_catalog_edit.php:74
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
$status
$status
Определения
session.php:10
Bitrix\Bizproc\Automation\Target
Определения
basetarget.php:2
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$i
$i
Определения
factura.php:643
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$iterator
$iterator
Определения
yandex_run.php:610
bitrix
modules
bizproc
lib
automation
target
basetarget.php
Создано системой
1.14.0