1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
activity.php
См. документацию.
1<?php
2
6
7abstract class CBPActivity
8{
9 use Bizproc\Debugger\Mixins\WriterDebugTrack;
10
11 public ?CBPActivity $parent = null;
12
15
16 private array $arStatusChangeHandlers = [];
17
18 public const StatusChangedEvent = 0;
19 public const ExecutingEvent = 1;
20 public const CancelingEvent = 2;
21 public const ClosedEvent = 3;
22 public const FaultingEvent = 4;
23
24 private const ValueSinglePattern = '\{=\s*(?<object>[a-z0-9_]+)\s*\:\s*(?<field>[a-z0-9_\.]+)(\s*>\s*(?<mod1>[a-z0-9_\:]+)(\s*,\s*(?<mod2>[a-z0-9_]+))?)?\s*\}';
25
26 public const ValuePattern = '#^\s*'.self::ValueSinglePattern.'\s*$#i';
27 private const ValueSimplePattern = '#^\s*\{\{(.*?)\}\}\s*$#i';
28 public const ValueInlinePattern = '#'.self::ValueSinglePattern.'#i';
30 public const ValueInternalPattern = '\{=\s*([a-z0-9_]+)\s*\:\s*([a-z0-9_\.]+)(\s*>\s*([a-z0-9_\:]+)(\s*,\s*([a-z0-9_]+))?)?\s*\}';
31
32 public const CalcPattern = '#^\s*(=\s*(.*)|\{\{=\s*(.*)\s*\}\})\s*$#is';
33 public const CalcInlinePattern = '#\{\{=\s*(.*?)\s*\}\}([^\}]|$)#is';
34
35 protected array $arProperties = [];
36 protected array $arPropertiesTypes = [];
37
38 protected string $name = '';
39 protected bool $activated = true;
41 public $workflow = null;
42
43 public array $arEventsMap = [];
44
45 protected int $resultPriority = 0;
46
47 /************************ PROPERTIES ************************************************/
48
52 public function getDocumentId()
53 {
54 return $this->getRootActivity()->getDocumentId();
55 }
56
61 public function setDocumentId($documentId)
62 {
63 $this->getRootActivity()->setDocumentId($documentId);
64 }
65
69 public function getDocumentType()
70 {
71 $rootActivity = $this->getRootActivity();
72 if (empty($rootActivity->documentType))
73 {
75 $documentService = $this->workflow->getService('DocumentService');
76 $rootActivity->setDocumentType(
77 $documentService->getDocumentType($rootActivity->getDocumentId())
78 );
79 }
80
81 return $rootActivity->documentType;
82 }
83
84 public function setDocumentType(array $documentType): void
85 {
86 $this->getRootActivity()->documentType = $documentType;
87 }
88
89 public function getDocumentEventType(): int
90 {
91 return (int)$this->getRootActivity()->getRawProperty(CBPDocument::PARAM_DOCUMENT_EVENT_TYPE);
92 }
93
97 public function getWorkflowStatus()
98 {
99 return $this->getRootActivity()->getWorkflowStatus();
100 }
101
102 public function setWorkflowStatus($status)
103 {
104 $this->getRootActivity()->setWorkflowStatus($status);
105 }
106
107 public function setFieldTypes(array $arFieldTypes = []): void
108 {
109 $rootActivity = $this->getRootActivity();
110 foreach ($arFieldTypes as $key => $value)
111 {
112 $rootActivity->arFieldTypes[$key] = $value;
113 }
114 }
115
119 public function getWorkflowTemplateId()
120 {
121 $rootActivity = $this->getRootActivity();
122 //prevent recursion by checking setter
123 if (method_exists($rootActivity, 'setWorkflowTemplateId'))
124 {
125 return $rootActivity->getWorkflowTemplateId();
126 }
127
128 return 0;
129 }
130
134 public function getTemplateUserId()
135 {
136 $userId = 0;
137 $rootActivity = $this->getRootActivity();
138 //prevent recursion by checking setter
139 if (method_exists($rootActivity, 'setTemplateUserId'))
140 {
141 $userId = $rootActivity->getTemplateUserId();
142 }
143
144 if (!$userId && $tplId = $this->getWorkflowTemplateId())
145 {
146 $userId = CBPWorkflowTemplateLoader::getTemplateUserId($tplId);
147 }
148
149 return $userId;
150 }
151
152 protected static function getPropertiesMap(array $documentType, array $context = []): array
153 {
154 return [];
155 }
156
157 /**********************************************************/
158 protected function clearProperties()
159 {
160 $rootActivity = $this->GetRootActivity();
161 $documentId = $rootActivity->GetDocumentId();
162 $documentType = $this->GetDocumentType();
164 $documentService = $this->workflow->GetService("DocumentService");
165
166 if (is_array($rootActivity->arPropertiesTypes) && count($rootActivity->arPropertiesTypes) > 0
167 && is_array($rootActivity->arFieldTypes) && count($rootActivity->arFieldTypes) > 0)
168 {
169 foreach ($rootActivity->arPropertiesTypes as $key => $value)
170 {
171 if ($rootActivity->arFieldTypes[$value["Type"]]["BaseType"] == "file")
172 {
173 foreach ((array) $rootActivity->__get($key) as $v)
174 {
175 if (intval($v) > 0)
176 {
177 $iterator = \CFile::getByID($v);
178 if ($file = $iterator->fetch())
179 {
180 if ($file['MODULE_ID'] === 'bizproc')
181 CFile::Delete($v);
182 }
183 }
184 }
185 }
186
187 $fieldType = \Bitrix\Bizproc\FieldType::normalizeProperty($value);
188 if ($fieldTypeObject = $documentService->getFieldTypeObject($documentType, $fieldType))
189 {
190 $fieldTypeObject->setDocumentId($documentId)
191 ->clearValue($rootActivity->arProperties[$key]);
192 }
193 }
194 }
195 }
196
197 public function getPropertyBaseType($propertyName)
198 {
199 $rootActivity = $this->GetRootActivity();
200 return $rootActivity->arFieldTypes[$rootActivity->arPropertiesTypes[$propertyName]["Type"]]["BaseType"];
201 }
202
203 public function getTemplatePropertyType($propertyName)
204 {
205 $rootActivity = $this->GetRootActivity();
206 if ($propertyName === 'TargetUser' && !isset($rootActivity->arPropertiesTypes[$propertyName]))
207 {
208 return ['Type' => 'user'];
209 }
210
211 return $rootActivity->arPropertiesTypes[$propertyName];
212 }
213
214 public function setProperties($arProperties = array())
215 {
216 if (count($arProperties) > 0)
217 {
218 foreach ($arProperties as $key => $value)
219 {
220 $this->arProperties[$key] = $value;
221 }
222 }
223 }
224
226 {
227 if (count($arPropertiesTypes) > 0)
228 {
229 foreach ($arPropertiesTypes as $key => $value)
230 {
231 $this->arPropertiesTypes[$key] = $value;
232 }
233 }
234 }
235
236 public function getPropertyType($propertyName): ?array
237 {
238 return $this->arPropertiesTypes[$propertyName] ?? null;
239 }
240
241 /**********************************************************/
242 protected function clearVariables()
243 {
244 $rootActivity = $this->GetRootActivity();
245 $documentId = $rootActivity->GetDocumentId();
246 $documentType = $this->GetDocumentType();
248 $documentService = $this->workflow->GetService("DocumentService");
249
250 if (is_array($rootActivity->arVariablesTypes) && count($rootActivity->arVariablesTypes) > 0
251 && is_array($rootActivity->arFieldTypes) && count($rootActivity->arFieldTypes) > 0)
252 {
253 foreach ($rootActivity->arVariablesTypes as $key => $value)
254 {
255 if (
256 isset($rootActivity->arFieldTypes[$value["Type"]])
257 && $rootActivity->arFieldTypes[$value["Type"]]["BaseType"] === "file"
258 )
259 {
260 foreach ((array) $rootActivity->arVariables[$key] as $v)
261 {
262 if (intval($v) > 0)
263 {
264 $iterator = \CFile::getByID($v);
265 if ($file = $iterator->fetch())
266 {
267 if ($file['MODULE_ID'] === 'bizproc')
268 CFile::Delete($v);
269 }
270 }
271 }
272 }
273
274 $fieldType = \Bitrix\Bizproc\FieldType::normalizeProperty($value);
275 if ($fieldTypeObject = $documentService->getFieldTypeObject($documentType, $fieldType))
276 {
277 $fieldTypeObject->setDocumentId($documentId)
278 ->clearValue($rootActivity->arVariables[$key]);
279 }
280 }
281 }
282 }
283
284 public function getVariableBaseType($variableName)
285 {
286 $rootActivity = $this->GetRootActivity();
287 return $rootActivity->arFieldTypes[$rootActivity->arVariablesTypes[$variableName]["Type"]]["BaseType"];
288 }
289
290 public function setVariables($variables = [])
291 {
292 if (!is_array($variables))
293 {
294 throw new CBPArgumentTypeException("variables", "array");
295 }
296
297 if (count($variables) > 0)
298 {
299 $rootActivity = $this->GetRootActivity();
300 foreach ($variables as $key => $value)
301 {
302 $rootActivity->arVariables[$key] = $value;
303 }
304 }
305 }
306
307 public function setVariablesTypes($arVariablesTypes = array())
308 {
309 if (count($arVariablesTypes) > 0)
310 {
311 $rootActivity = $this->GetRootActivity();
312 foreach ($arVariablesTypes as $key => $value)
313 $rootActivity->arVariablesTypes[$key] = $value;
314 }
315 }
316
317 public function setVariable($name, $value)
318 {
319 $rootActivity = $this->GetRootActivity();
320 $rootActivity->arVariables[$name] = $value;
321 }
322
323 public function getVariable($name)
324 {
325 $rootActivity = $this->GetRootActivity();
326
327 if (array_key_exists($name, $rootActivity->arVariables))
328 {
329 return $rootActivity->arVariables[$name];
330 }
331
332 return null;
333 }
334
335 public function getVariableType($name)
336 {
337 $rootActivity = $this->GetRootActivity();
338 return isset($rootActivity->arVariablesTypes[$name]) ? $rootActivity->arVariablesTypes[$name] : null;
339 }
340
341 private function getConstantTypes()
342 {
343 $rootActivity = $this->GetRootActivity();
344 if (method_exists($rootActivity, 'GetWorkflowTemplateId'))
345 {
346 $templateId = $rootActivity->GetWorkflowTemplateId();
347 if ($templateId > 0)
348 {
349 return CBPWorkflowTemplateLoader::getTemplateConstants($templateId);
350 }
351 }
352 return null;
353 }
354
355 public function getConstant($name)
356 {
357 $constants = $this->GetConstantTypes();
358 if (isset($constants[$name]['Default']))
359 return $constants[$name]['Default'];
360 return null;
361 }
362
363 public function getConstantType($name)
364 {
365 $constants = $this->GetConstantTypes();
366 if (isset($constants[$name]))
367 return $constants[$name];
368 return array('Type' => null, 'Multiple' => false, 'Required' => false, 'Options' => null);
369 }
370
371 public function isVariableExists($name)
372 {
373 $rootActivity = $this->GetRootActivity();
374 $variables = $rootActivity->arVariables ?? [];
375 $variablesTypes = $rootActivity->arVariablesTypes ?? [];
376
377 return (
378 array_key_exists($name, $variables)
379 || array_key_exists($name, $variablesTypes)
380 );
381 }
382
383 /************************************************/
384 public function getName(): string
385 {
386 return $this->name;
387 }
388
389 public function getRootActivity(): CBPActivity
390 {
391 if ($this->workflow)
392 {
393 return $this->workflow->getRootActivity();
394 }
395
396 $p = $this;
397 while ($p->parent !== null)
398 {
399 $p = $p->parent;
400 }
401
402 return $p;
403 }
404
406 {
407 $this->workflow = $workflow;
408 }
409
410 public function unsetWorkflow()
411 {
412 $this->workflow = null;
413 }
414
415 public function getWorkflowInstanceId()
416 {
417 return $this->workflow->GetInstanceId();
418 }
419
420 public function setStatusTitle($title = '')
421 {
422 $rootActivity = $this->GetRootActivity();
423 $stateService = $this->workflow->GetService("StateService");
424 if ($rootActivity instanceof CBPStateMachineWorkflowActivity)
425 {
426 $arState = $stateService->GetWorkflowState($this->GetWorkflowInstanceId());
427
428 $arActivities = $rootActivity->CollectNestedActivities();
430 foreach ($arActivities as $activity)
431 if ($activity->GetName() == $arState["STATE_NAME"])
432 break;
433
434 $stateService->SetStateTitle(
435 $this->GetWorkflowInstanceId(),
436 $activity->Title.($title != '' ? ": ".$title : '')
437 );
438 }
439 else
440 {
441 if ($title != '')
442 {
443 $stateService->SetStateTitle(
444 $this->GetWorkflowInstanceId(),
445 $title
446 );
447 }
448 }
449 }
450
451 public function addStatusTitle($title = '')
452 {
453 if ($title == '')
454 return;
455
456 $stateService = $this->workflow->GetService("StateService");
457
458 $mainTitle = $stateService->GetStateTitle($this->GetWorkflowInstanceId());
459 $mainTitle .= ((mb_strpos($mainTitle, ": ") !== false) ? ", " : ": ").$title;
460
461 $stateService->SetStateTitle($this->GetWorkflowInstanceId(), $mainTitle);
462 }
463
464 public function deleteStatusTitle($title = '')
465 {
466 if ($title == '')
467 return;
468
469 $stateService = $this->workflow->GetService("StateService");
470 $mainTitle = $stateService->GetStateTitle($this->GetWorkflowInstanceId());
471
472 $ar1 = explode(":", $mainTitle);
473 if (count($ar1) <= 1)
474 return;
475
476 $newTitle = "";
477
478 $ar2 = explode(",", $ar1[1]);
479 foreach ($ar2 as $a)
480 {
481 $a = trim($a);
482 if ($a != $title)
483 {
484 if ($newTitle <> '')
485 $newTitle .= ", ";
486 $newTitle .= $a;
487 }
488 }
489
490 $result = $ar1[0].($newTitle <> '' ? ": " : "").$newTitle;
491
492 $stateService->SetStateTitle($this->GetWorkflowInstanceId(), $result);
493 }
494
495 private function getPropertyValueRecursive($val, $convertToType = null, ?callable $decorator = null)
496 {
497 // array(2, 5, array("SequentialWorkflowActivity1", "DocumentApprovers"))
498 // array("Document", "IBLOCK_ID")
499 // array("Workflow", "id")
500 // "Hello, {=SequentialWorkflowActivity1:DocumentApprovers}, {=Document:IBLOCK_ID}!"
501
502 $parsed = static::parseExpression($val);
503 if ($parsed)
504 {
505 $result = null;
506 if ($convertToType)
507 $parsed['modifiers'][] = $convertToType;
508 $this->getRealParameterValue(
509 $parsed['object'],
510 $parsed['field'],
511 $result,
512 $parsed['modifiers'],
513 $decorator
514 );
515 return array(1, $result);
516 }
517 elseif (is_array($val))
518 {
519 $b = true;
520 $r = array();
521
522 $keys = array_keys($val);
523
524 $i = 0;
525 foreach ($keys as $key)
526 {
527 if ($key."!" != $i."!")
528 {
529 $b = false;
530 break;
531 }
532 $i++;
533 }
534
535 foreach ($keys as $key)
536 {
537 [$t, $a] = $this->GetPropertyValueRecursive($val[$key], $convertToType, $decorator);
538 if ($b)
539 {
540 if ($t == 1 && is_array($a))
541 $r = array_merge($r, $a);
542 else
543 $r[] = $a;
544 }
545 else
546 {
547 $r[$key] = $a;
548 }
549 }
550
551 if (count($r) == 2)
552 {
553 $keys = array_keys($r);
554 if ($keys[0] == 0 && $keys[1] == 1 && is_string($r[0]) && is_string($r[1]))
555 {
556 $result = null;
557 $modifiers = $convertToType ? array($convertToType) : array();
558 if ($this->GetRealParameterValue($r[0], $r[1], $result, $modifiers, $decorator))
559 return array(1, $result);
560 }
561 }
562 return array(2, $r);
563 }
564 else
565 {
566 if (is_string($val))
567 {
568 $typeClass = null;
569 $fieldTypeObject = null;
570 if ($convertToType)
571 {
573 $documentService = $this->workflow->GetService("DocumentService");
574 $documentType = $this->GetDocumentType();
575
576 $typesMap = $documentService->getTypesMap($documentType);
577 $convertToType = mb_strtolower($convertToType);
578 if (isset($typesMap[$convertToType]))
579 {
580 $typeClass = $typesMap[$convertToType];
581 $fieldTypeObject = $documentService->getFieldTypeObject(
582 $documentType,
583 array('Type' => \Bitrix\Bizproc\FieldType::STRING)
584 );
585 }
586 }
587
588 $calc = new Bizproc\Calc\Parser($this);
589 if (preg_match(self::CalcPattern, $val))
590 {
591 $r = $calc->Calculate($val);
592 if ($r !== null)
593 {
594 if ($typeClass && $fieldTypeObject)
595 {
596 if (is_array($r))
597 $fieldTypeObject->setMultiple(true);
598 $r = $fieldTypeObject->convertValue($r, $typeClass);
599 }
600 return array(is_array($r)? 1 : 2, $r);
601 }
602 }
603
604 //parse inline calculator
605 $val = preg_replace_callback(
606 static::CalcInlinePattern,
607 function($matches) use ($calc)
608 {
609 $r = $calc->Calculate($matches[1]);
610 if (is_array($r))
611 $r = implode(', ', CBPHelper::MakeArrayFlat($r));
612 return $r !== null? $r.$matches[2] : $matches[0];
613 },
614 $val
615 );
616
617 //parse properties
618 $val = preg_replace_callback(
619 static::ValueInlinePattern,
620 fn($matches) => $this->parseStringParameter($matches, $convertToType, $decorator),
621 $val
622 );
623
624 //converting...
625 if ($typeClass && $fieldTypeObject)
626 {
627 $val = $fieldTypeObject->convertValue($val, $typeClass);
628 }
629 }
630
631 return array(2, $val);
632 }
633 }
634
635 private function getRealParameterValue(
636 $objectName,
637 $fieldName,
638 &$result,
639 array $modifiers = null,
640 ?callable $decorator = null
641 )
642 {
643 $return = true;
644 $property = null;
646 $documentService = $this->workflow->GetService("DocumentService");
647
648 if ($objectName === "Document")
649 {
650 $rootActivity = $this->GetRootActivity();
651 $documentId = $rootActivity->GetDocumentId();
652
653 $documentType = $this->GetDocumentType();
654 $usedDocumentFields = $rootActivity->{CBPDocument::PARAM_USED_DOCUMENT_FIELDS} ?? [];
655 $document = $documentService->GetDocument($documentId, $documentType, $usedDocumentFields);
656 $documentFields = $documentService->GetDocumentFields($documentType);
657 //check aliases
658 $documentFieldsAliasesMap = CBPDocument::getDocumentFieldsAliasesMap($documentFields);
659 if (!isset($document[$fieldName]) && mb_strtoupper(mb_substr($fieldName, -10)) === '_PRINTABLE')
660 {
661 $fieldName = mb_substr($fieldName, 0, -10);
662 if (!in_array('printable', $modifiers))
663 {
664 $modifiers[] = 'printable';
665 }
666 }
667 if (!isset($document[$fieldName]) && isset($documentFieldsAliasesMap[$fieldName]))
668 {
669 $fieldName = $documentFieldsAliasesMap[$fieldName];
670 }
671
672 $result = '';
673
674 if (isset($document[$fieldName]))
675 {
676 $result = $document[$fieldName];
677 if (is_array($result) && mb_strtoupper(mb_substr($fieldName, -10)) === '_PRINTABLE')
678 {
679 $result = implode(", ", CBPHelper::MakeArrayFlat($result));
680 }
681
682 $property = isset($documentFields[$fieldName]) ? $documentFields[$fieldName] : null;
683 }
684 }
685 elseif (in_array($objectName, ['Template', 'Variable', 'Constant']))
686 {
687 $rootActivity = $this->GetRootActivity();
688
689 if (mb_substr($fieldName, -10) == "_printable")
690 {
691 $fieldName = mb_substr($fieldName, 0, -10);
692 $modifiers = ['printable'];
693 }
694
695 switch ($objectName)
696 {
697 case 'Variable':
698 $result = $rootActivity->GetVariable($fieldName);
699 $property = $rootActivity->getVariableType($fieldName);
700 break;
701 case 'Constant':
702 $result = $rootActivity->GetConstant($fieldName);
703 $property = $rootActivity->GetConstantType($fieldName);
704 break;
705 default:
706 $result = $rootActivity->__get($fieldName);
707 $property = $rootActivity->getTemplatePropertyType($fieldName);
708 }
709 }
710 elseif ($objectName === 'GlobalConst')
711 {
712 $property = Bizproc\Workflow\Type\GlobalConst::getById($fieldName);
713 if (!$property && mb_substr($fieldName, -10) == "_printable")
714 {
715 $fieldName = mb_substr($fieldName, 0, -10);
716 $modifiers = ['printable'];
717 $property = Bizproc\Workflow\Type\GlobalConst::getById($fieldName);
718 }
719
720 $result = Bizproc\Workflow\Type\GlobalConst::getValue($fieldName);
721 }
722 elseif ($objectName === 'GlobalVar')
723 {
724 $property = Bizproc\Workflow\Type\GlobalVar::getById($fieldName);
725 if (!$property && mb_substr($fieldName, -10) == "_printable")
726 {
727 $fieldName = mb_substr($fieldName, 0, -10);
728 $modifiers = ['printable'];
729 $property = Bizproc\Workflow\Type\GlobalVar::getById($fieldName);
730 }
731
732 $result = Bizproc\Workflow\Type\GlobalVar::getValue($fieldName);
733 }
734 elseif ($objectName === "Workflow")
735 {
736 $result = $this->GetWorkflowInstanceId();
737 $property = array('Type' => 'string');
738 }
739 elseif ($objectName === "User")
740 {
741 if (mb_substr($fieldName, -10) == "_printable")
742 {
743 $modifiers = ['printable'];
744 }
745
746 $result = 0;
747 if (isset($GLOBALS["USER"]) && is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->isAuthorized())
748 {
749 $result = "user_".$GLOBALS["USER"]->GetID();
750 }
751 $property = array('Type' => 'user');
752 }
753 elseif ($objectName === "System")
754 {
755 if (mb_substr($fieldName, -10) === "_printable")
756 {
757 $fieldName = mb_substr($fieldName, 0, -10);
758 $modifiers = ['printable'];
759 }
760
761 $result = null;
762 $property = array('Type' => 'datetime');
763 $systemField = mb_strtolower($fieldName);
764 if ($systemField === 'now')
765 {
766 $result = new Bizproc\BaseType\Value\DateTime();
767 }
768 elseif ($systemField === 'nowlocal')
769 {
770 $result = new Bizproc\BaseType\Value\DateTime(time(), CTimeZone::GetOffset());
771 }
772 elseif ($systemField === 'date')
773 {
774 $result = new Bizproc\BaseType\Value\Date();
775 $property = array('Type' => 'date');
776 }
777 elseif ($systemField === 'eol')
778 {
779 $result = PHP_EOL;
780 $property = ['Type' => 'string'];
781 }
782 elseif ($systemField === 'hosturl')
783 {
784 $result = Main\Engine\UrlManager::getInstance()->getHostUrl();
785 $property = ['Type' => 'string'];
786 }
787
788 if ($result === null)
789 {
790 $return = false;
791 }
792 }
793 elseif ($objectName)
794 {
795 $activity = $this->workflow->GetActivityByName($objectName);
796 if ($activity)
797 {
798 $result = $activity->__get($fieldName);
799 $property = $activity->getPropertyType($fieldName);
800 }
801 else
802 $return = false;
803 }
804 else
805 $return = false;
806
807 if ($property && $result)
808 {
809 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
810 if ($fieldTypeObject)
811 {
812 $fieldTypeObject->setDocumentId($this->GetDocumentId());
813 $result = $fieldTypeObject->internalizeValue($objectName, $result);
814 }
815 }
816
817 if ($return)
818 {
819 $result = $this->applyPropertyValueModifiers($fieldName, $property, $result, $modifiers);
820
821 if ($decorator)
822 {
823 $result = $decorator($objectName, $fieldName, $property, $result);
824 }
825 }
826 return $return;
827 }
828
829 public function getRuntimeProperty($object, $field, CBPActivity $ownerActivity): array
830 {
831 $rootActivity = $ownerActivity->getRootActivity();
832 $documentType = $rootActivity->getDocumentType();
833 $usedDocumentFields = $rootActivity->{CBPDocument::PARAM_USED_DOCUMENT_FIELDS} ?? [];
834
835 $result = null;
836 $property = null;
837
838 if (CBPHelper::isEmptyValue($object))
839 {
840 return [$property, $result];
841 }
842 elseif ($object === 'Template' || $object === Bizproc\Workflow\Template\SourceType::Parameter)
843 {
844 $result = $rootActivity->__get($field);
845 $property = $rootActivity->getTemplatePropertyType($field);
846 }
847 elseif ($object === Bizproc\Workflow\Template\SourceType::Variable)
848 {
849 $result = $rootActivity->getVariable($field);
850 $property = $rootActivity->getVariableType($field);
851 }
852 elseif ($object === Bizproc\Workflow\Template\SourceType::Constant)
853 {
854 $result = $rootActivity->getConstant($field);
855 $property = $rootActivity->getConstantType($field);
856 }
857 elseif ($object === Bizproc\Workflow\Template\SourceType::GlobalConstant)
858 {
859 $result = Bizproc\Workflow\Type\GlobalConst::getValue($field);
860 $property = Bizproc\Workflow\Type\GlobalConst::getVisibleById($field, $documentType);
861 }
862 elseif ($object === Bizproc\Workflow\Template\SourceType::GlobalVariable)
863 {
864 $result = Bizproc\Workflow\Type\GlobalVar::getValue($field);
865 $property = Bizproc\Workflow\Type\GlobalVar::getVisibleById($field, $documentType);
866 }
867 elseif ($object === Bizproc\Workflow\Template\SourceType::DocumentField)
868 {
869 $documentService = CBPRuntime::getRuntime()->getDocumentService();
870 $documentFields = $documentService->GetDocumentFields($documentType);
871 $documentId = $rootActivity->getDocumentId();
872 $property = $documentFields[$field] ?? null;
873 $result = $documentService->getFieldValue($documentId, $field, $documentType, $usedDocumentFields);
874 }
875 else
876 {
877 $activity = $rootActivity->workflow->getActivityByName($object);
878 if ($activity)
879 {
880 $result = $activity->__get($field);
881 $property = $activity->getPropertyType($field);
882 }
883 }
884
885 if (!$property)
886 {
887 $property = ['Type' => 'string'];
888 }
889
890 return [$property, $result];
891 }
892
893 private function applyPropertyValueModifiers($fieldName, $property, $value, array $modifiers)
894 {
895 if (empty($property) || empty($modifiers) || !is_array($property))
896 return $value;
897
898 $typeName = null;
899 $typeClass = null;
900 $format = null;
901 $modifiers = array_slice($modifiers, 0, 2);
902
903 $rootActivity = $this->GetRootActivity();
904 $documentId = $rootActivity->GetDocumentId();
906 $documentService = $this->workflow->GetService("DocumentService");
907 $documentType = $this->GetDocumentType();
908
909 $typesMap = $documentService->getTypesMap($documentType);
910 foreach ($modifiers as $m)
911 {
912 $m = mb_strtolower($m);
913 if (isset($typesMap[$m]))
914 {
915 $typeName ??= $m;
916 $typeClass ??= $typesMap[$m];
917 }
918 else
919 {
920 $format = $m;
921 }
922 }
923
924 $priority = $format && array_search($format, $modifiers) === 0 ? 'format' : 'type';
925
926 if ($typeName === \Bitrix\Bizproc\FieldType::STRING && $format === 'printable')
927 {
928 $typeClass = null;
929 }
930
931 if ($typeClass || $format)
932 {
933 $fieldTypeObject = $documentService->getFieldTypeObject($documentType, $property);
934
935 if ($fieldTypeObject)
936 {
937 $fieldTypeObject->setDocumentId($documentId);
938
939 if ($format && $priority === 'format')
940 {
941 $value = $fieldTypeObject->formatValue($value, $format);
942 //$value becomes String
943 $fieldTypeObject->setTypeClass(Bizproc\BaseType\StringType::class);
944 }
945
946 if ($typeClass)
947 {
948 $value = $fieldTypeObject->convertValue($value, $typeClass);
949 }
950
951 if ($format && $priority !== 'format')
952 {
953 $value = $fieldTypeObject->formatValue($value, $format);
954 }
955 }
956 elseif ($format == 'printable') // compatibility: old printable style
957 {
958 $value = $documentService->GetFieldValuePrintable(
959 $documentId,
960 $fieldName,
961 $property['Type'],
962 $value,
963 $property
964 );
965
966 if (is_array($value))
967 $value = implode(", ", CBPHelper::MakeArrayFlat($value));
968 }
969 }
970
971 return $value;
972 }
973
974 private function parseStringParameter($matches, $convertToType = null, ?callable $decorator = null)
975 {
976 $result = "";
977 $modifiers = [];
978 if (!empty($matches['mod1']))
979 {
980 $modifiers[] = $matches['mod1'];
981 }
982 if (!empty($matches['mod2']))
983 {
984 $modifiers[] = $matches['mod2'];
985 }
986 if ($convertToType)
987 {
988 $modifiers[] = $convertToType;
989 }
990
991 if (empty($modifiers))
992 {
993 $modifiers[] = \Bitrix\Bizproc\FieldType::STRING;
994 }
995
996 if ($this->getRealParameterValue($matches['object'], $matches['field'], $result, $modifiers, $decorator))
997 {
998 if (is_array($result))
999 {
1000 $result = implode(", ", CBPHelper::MakeArrayFlat($result));
1001 }
1002 }
1003 else
1004 {
1005 $result = $matches[0];
1006 }
1007
1008 return $result;
1009 }
1010
1011 public function parseValue($value, $convertToType = null, ?callable $decorator = null)
1012 {
1013 [$t, $r] = $this->getPropertyValueRecursive($value, $convertToType, $decorator);
1014
1015 return $r;
1016 }
1017
1018 protected function getRawProperty($name)
1019 {
1020 if (isset($this->arProperties[$name]))
1021 {
1022 return $this->arProperties[$name];
1023 }
1024 else
1025 {
1026 $ro = $this->getRootActivity()->getReadOnlyData();
1027 if (isset($ro[$this->getName()]) && isset($ro[$this->getName()][$name]))
1028 {
1029 return $ro[$this->getName()][$name];
1030 }
1031 }
1032
1033 return null;
1034 }
1035
1036 public function __get($name)
1037 {
1038 $property = $this->getRawProperty($name);
1039 if ($property !== null)
1040 {
1041 [$t, $r] = $this->GetPropertyValueRecursive($property);
1042 return $r;
1043 }
1044 return null;
1045 }
1046
1047 public function __isset($name)
1048 {
1049 return $this->isPropertyExists($name);
1050 }
1051
1052 public function pullProperties(): array
1053 {
1055 $this->arProperties = array_fill_keys(array_keys($this->arProperties), null);
1056
1057 return [$this->getName() => $result];
1058 }
1059
1060 public function __set($name, $val)
1061 {
1062 if (array_key_exists($name, $this->arProperties))
1063 {
1064 $this->arProperties[$name] = $val;
1065 }
1066 }
1067
1068 public function isPropertyExists($name)
1069 {
1070 return array_key_exists($name, $this->arProperties);
1071 }
1072
1073 public function collectNestedActivities()
1074 {
1075 return null;
1076 }
1077
1078 public function collectUsages()
1079 {
1080 $usages = [];
1081 $this->collectUsagesRecursive($this->arProperties, $usages);
1082 return $usages;
1083 }
1084
1085 public function collectPropertyUsages($propertyName): array
1086 {
1087 $usages = [];
1088 $this->collectUsagesRecursive($this->getRawProperty($propertyName), $usages);
1089
1090 return $usages;
1091 }
1092
1093 protected function collectUsagesRecursive($val, &$usages)
1094 {
1095 if (is_array($val))
1096 {
1097 foreach ($val as $v)
1098 {
1099 $this->collectUsagesRecursive($v, $usages);
1100 }
1101 }
1102 elseif (is_string($val))
1103 {
1104 $parsed = static::parseExpression($val);
1105 if ($parsed)
1106 {
1107 $usages[] = $this->getObjectSourceType($parsed['object'], $parsed['field']);
1108 }
1109 else
1110 {
1111 //TODO: check calc functions
1112 /*$calc = new CBPCalc($this);
1113 if (preg_match(self::CalcPattern, $val))
1114 {
1115 $r = $calc->Calculate($val);
1116
1117 }
1118
1119 //parse inline calculator
1120 $val = preg_replace_callback(
1121 static::CalcInlinePattern,
1122 function($matches) use ($calc)
1123 {
1124 $r = $calc->Calculate($matches[1]);
1125
1126 },
1127 $val
1128 );*/
1129
1130 //parse properties
1131 $val = preg_replace_callback(
1132 static::ValueInlinePattern,
1133 function($matches) use (&$usages)
1134 {
1135 $usages[] = $this->getObjectSourceType($matches['object'], $matches['field']);
1136 },
1137 $val
1138 );
1139 }
1140 }
1141 }
1142
1143 protected function getObjectSourceType($objectName, $fieldName)
1144 {
1145 return \Bitrix\Bizproc\Workflow\Template\SourceType::getObjectSourceType($objectName, $fieldName);
1146 }
1147
1148 /************************ CONSTRUCTORS *****************************************************/
1149
1150 public function __construct($name)
1151 {
1152 $this->name = $name;
1153 }
1154
1155 /************************ DEBUG ***********************************************************/
1156
1157 public function toString()
1158 {
1159 return $this->name.
1160 " [".get_class($this)."] (status=".
1161 CBPActivityExecutionStatus::Out($this->executionStatus).
1162 ", result=".
1163 CBPActivityExecutionResult::Out($this->executionResult).
1164 ", count(ClosedEvent)=".
1165 count($this->arStatusChangeHandlers[self::ClosedEvent]).
1166 ")";
1167 }
1168
1169 public function dump($level = 3)
1170 {
1171 $result = str_repeat(" ", $level).$this->ToString()."\n";
1172
1173 if (is_subclass_of($this, "CBPCompositeActivity"))
1174 {
1176 foreach ($this->arActivities as $activity)
1177 $result .= $activity->Dump($level + 1);
1178 }
1179
1180 return $result;
1181 }
1182
1183 /************************ PROCESS ***********************************************************/
1184
1185 public function initialize()
1186 {
1187 }
1188
1189 public function finalize()
1190 {
1191 }
1192
1193 public function execute()
1194 {
1196 }
1197
1198 protected function reInitialize()
1199 {
1200 $this->executionStatus = CBPActivityExecutionStatus::Initialized;
1201 $this->executionResult = CBPActivityExecutionResult::None;
1202 }
1203
1204 public function cancel()
1205 {
1207 }
1208
1209 public function handleFault(Exception $exception)
1210 {
1211 $status = $this->cancel();
1213 {
1215 }
1216
1217 return $status;
1218 }
1219
1220 /************************ LOAD / SAVE *******************************************************/
1221
1222 public function fixUpParentChildRelationship(CBPActivity $nestedActivity)
1223 {
1224 $nestedActivity->parent = $this;
1225 }
1226
1227 public static function load($stream)
1228 {
1229 if ($stream == '')
1230 {
1231 throw new CBPArgumentNullException("stream");
1232 }
1233
1234 return CBPRuntime::GetRuntime()->unserializeWorkflowStream($stream);
1235 }
1236
1237 protected function getACNames()
1238 {
1239 return array(mb_substr(get_class($this), 3));
1240 }
1241
1242 private static function searchUsedActivities(CBPActivity $activity, &$arUsedActivities)
1243 {
1244 $arT = $activity->GetACNames();
1245 foreach ($arT as $t)
1246 {
1247 if (!in_array($t, $arUsedActivities))
1248 {
1249 $arUsedActivities[] = $t;
1250 }
1251 }
1252
1253 if ($arNestedActivities = $activity->CollectNestedActivities())
1254 {
1255 foreach ($arNestedActivities as $nestedActivity)
1256 {
1257 self::SearchUsedActivities($nestedActivity, $arUsedActivities);
1258 }
1259 }
1260 }
1261
1262 public function save()
1263 {
1264 $usedActivities = [];
1265 self::SearchUsedActivities($this, $usedActivities);
1266
1267 if ($children = $this->collectNestedActivities())
1268 {
1270 foreach ($children as $child)
1271 {
1272 $child->unsetWorkflow();
1273 }
1274 }
1275
1276 $strUsedActivities = implode(",", $usedActivities);
1277 return $strUsedActivities.";".serialize($this);
1278 }
1279
1280 /************************ STATUS CHANGE HANDLERS **********************************************/
1281
1282 public function addStatusChangeHandler($event, $eventHandler)
1283 {
1284 if (!is_array($this->arStatusChangeHandlers))
1285 $this->arStatusChangeHandlers = array();
1286
1287 if (!array_key_exists($event, $this->arStatusChangeHandlers))
1288 $this->arStatusChangeHandlers[$event] = array();
1289
1290 $this->arStatusChangeHandlers[$event][] = $eventHandler;
1291 }
1292
1293 public function removeStatusChangeHandler($event, $eventHandler)
1294 {
1295 if (!is_array($this->arStatusChangeHandlers))
1296 $this->arStatusChangeHandlers = array();
1297
1298 if (!array_key_exists($event, $this->arStatusChangeHandlers))
1299 $this->arStatusChangeHandlers[$event] = array();
1300
1301 $index = array_search($eventHandler, $this->arStatusChangeHandlers[$event], true);
1302
1303 if ($index !== false)
1304 unset($this->arStatusChangeHandlers[$event][$index]);
1305 }
1306
1307 /************************ EVENTS **********************************************************************/
1308
1309 private function fireStatusChangedEvents($event, $arEventParameters = array())
1310 {
1311 if (array_key_exists($event, $this->arStatusChangeHandlers) && is_array($this->arStatusChangeHandlers[$event]))
1312 {
1313 foreach ($this->arStatusChangeHandlers[$event] as $eventHandler)
1314 call_user_func_array(array($eventHandler, "OnEvent"), array($this, $arEventParameters));
1315 }
1316 }
1317
1318 public function setStatus($newStatus, $arEventParameters = array())
1319 {
1320 $this->executionStatus = $newStatus;
1321 $this->fireStatusChangedEvents(self::StatusChangedEvent, $arEventParameters);
1322
1323 switch ($newStatus)
1324 {
1326 $this->fireStatusChangedEvents(self::ExecutingEvent, $arEventParameters);
1327 break;
1328
1330 $this->fireStatusChangedEvents(self::CancelingEvent, $arEventParameters);
1331 break;
1332
1334 $this->fireStatusChangedEvents(self::ClosedEvent, $arEventParameters);
1335 break;
1336
1338 $this->fireStatusChangedEvents(self::FaultingEvent, $arEventParameters);
1339 break;
1340
1341 default:
1342 return;
1343 }
1344 }
1345
1346 /************************ CREATE *****************************************************************/
1347
1348 public static function includeActivityFile($code)
1349 {
1350 return CBPRuntime::getRuntime()->includeActivityFile($code);
1351 }
1352
1359 public static function createInstance($code, $name)
1360 {
1361 if (preg_match("#[^a-zA-Z0-9_]#", $code))
1362 {
1363 throw new CBPArgumentOutOfRangeException("Activity '" . $code . "' is not valid");
1364 }
1365
1366 $classname = 'CBP' . $code;
1367 if (class_exists($classname))
1368 {
1369 return new $classname($name);
1370 }
1371
1372 return null;
1373 }
1374
1375 public static function callStaticMethod($code, $method, $arParameters = array())
1376 {
1377 $runtime = CBPRuntime::GetRuntime();
1378 if (!$runtime->IncludeActivityFile($code))
1379 {
1380 return [
1381 [
1382 "code" => "ActivityNotFound",
1383 "parameter" => $code,
1384 "message" => GetMessage("BPGA_ACTIVITY_NOT_FOUND_1", ['#ACTIVITY#' => htmlspecialcharsbx($code)]),
1385 ],
1386 ];
1387 }
1388
1389 if (preg_match("#[^a-zA-Z0-9_]#", $code))
1390 {
1391 throw new CBPArgumentOutOfRangeException("Activity '".$code."' is not valid");
1392 }
1393
1394 if (strpos($code, 'CBP') === 0)
1395 {
1396 $code = mb_substr($code, 3);
1397 }
1398
1399 $classname = 'CBP'.$code;
1400
1401 if (method_exists($classname,$method))
1402 {
1403 return call_user_func_array(array($classname, $method), $arParameters);
1404 }
1405
1406 return false;
1407 }
1408
1410 {
1411 if (is_array($arParams))
1412 {
1413 foreach ($arParams as $key => $value)
1414 {
1415 if (array_key_exists($key, $this->arProperties))
1416 {
1417 $this->arProperties[$key] = $value;
1418 }
1419 }
1420 }
1421 }
1422
1423 /************************ MARK ****************************************************************/
1424
1425 public function markCanceled($arEventParameters = [])
1426 {
1427 if ($this->executionStatus != CBPActivityExecutionStatus::Closed)
1428 {
1429 if ($this->executionStatus != CBPActivityExecutionStatus::Canceling)
1430 {
1431 throw new CBPInvalidOperationException("InvalidCancelActivityState");
1432 }
1433
1434 $this->executionResult = CBPActivityExecutionResult::Canceled;
1435 $this->markClosed($arEventParameters);
1436 }
1437 }
1438
1439 public function markCompleted($arEventParameters = [])
1440 {
1441 $this->executionResult = CBPActivityExecutionResult::Succeeded;
1442 $this->markClosed($arEventParameters);
1443 }
1444
1445 public function markFaulted($arEventParameters = [])
1446 {
1447 $this->executionResult = CBPActivityExecutionResult::Faulted;
1448 $this->markClosed($arEventParameters);
1449 }
1450
1451 private function markClosed($arEventParameters = [])
1452 {
1453 switch ($this->executionStatus)
1454 {
1458 {
1459 if ($this instanceof \CBPCompositeActivity)
1460 {
1461 foreach ($this->arActivities as $activity)
1462 {
1463 if (
1465 && ($activity->executionStatus != CBPActivityExecutionStatus::Closed)
1466 )
1467 {
1468 throw new CBPInvalidOperationException('ActiveChildExist');
1469 }
1470 }
1471 }
1472
1473 if ($this->isActivated())
1474 {
1476 $trackingService = $this->workflow->getService('TrackingService');
1477 $trackingService->write(
1478 $this->getWorkflowInstanceId(),
1480 $this->getName(),
1481 $this->executionStatus,
1482 $this->executionResult,
1483 $this->getTitle()
1484 );
1485 }
1486 $this->setStatus(CBPActivityExecutionStatus::Closed, $arEventParameters);
1487
1488 return;
1489 }
1490 }
1491
1492 throw new CBPInvalidOperationException('InvalidCloseActivityState');
1493 }
1494
1495 protected function writeToTrackingService($message = "", $modifiedBy = 0, $trackingType = -1)
1496 {
1498 $trackingService = $this->workflow->GetService("TrackingService");
1499 if ($trackingType < 0)
1500 $trackingType = CBPTrackingType::Custom;
1501 $trackingService->Write($this->GetWorkflowInstanceId(), $trackingType, $this->name, $this->executionStatus, $this->executionResult, ($this->IsPropertyExists("Title") ? $this->Title : ""), $message, $modifiedBy);
1502 }
1503
1504 protected function fixResult(Bitrix\Bizproc\Result\ResultDto $result): void
1505 {
1506 $workflowId = $this->getWorkflowInstanceId();
1507 try
1508 {
1510 'WORKFLOW_ID' => $workflowId,
1511 'PRIORITY' => $this->resultPriority,
1512 'ACTIVITY' => $result->activity,
1513 'RESULT' => $result->data,
1514 ]);
1515 }
1516 catch (Throwable $e)
1517 {
1518 $this->trackError($e->getMessage());
1519 }
1520 }
1521
1522 public static function renderResult(array $result, string $workflowId, int $userId): RenderedResult
1523 {
1524 if (!self::checkResultViewRights($result, $workflowId, $userId))
1525 {
1526
1527 return RenderedResult::makeNoRights();
1528 }
1529
1530 $documentService = CBPRuntime::getRuntime()->getDocumentService();
1531
1532 if (isset($result['DOCUMENT_ID']))
1533 {
1534 $url = $documentService->getDocumentDetailUrl($result['DOCUMENT_ID']);
1535 $name = $documentService->getDocumentName($result['DOCUMENT_ID']);
1536 if (isset($result['DOCUMENT_TYPE']))
1537 {
1538 $type = (string)$documentService->getDocumentTypeCaption($result['DOCUMENT_TYPE']);
1539 $name = $type . ': ' . $name;
1540 }
1541
1542 return new RenderedResult('[URL=' . $url . ']' . $name . '[/URL]', RenderedResult::BB_CODE_RESULT);
1543 }
1544
1545 return RenderedResult::makeNoResult();
1546 }
1547
1548 protected static function checkResultViewRights(array $result, string $workflowId, int $userId): bool
1549 {
1550 $currentUser = new \CBPWorkflowTemplateUser($userId);
1551 $userCanReadDocument = false;
1552
1553 if (isset($result['DOCUMENT_ID']))
1554 {
1555 $userCanReadDocument = \CBPDocument::canUserOperateDocument(
1557 $currentUser->getId(),
1558 $result['DOCUMENT_ID'],
1559 );
1560 }
1561
1562 return
1563 $currentUser->isAdmin()
1564 || self::checkUserAccessWithSubordination($currentUser->getId(), $result['USERS'] ?? [])
1565 || $userCanReadDocument;
1566 }
1567
1568 protected static function checkUserAccessWithSubordination(int $userId, array $users): bool
1569 {
1570 if (in_array($userId, $users, true))
1571 {
1572 return true;
1573 }
1574 foreach ($users as $user)
1575 {
1576 if (\CBPHelper::checkUserSubordination($userId, $user))
1577 {
1578 return true;
1579 }
1580 }
1581
1582 return false;
1583 }
1584
1585 protected function trackError(string $errorMsg)
1586 {
1587 $this->writeToTrackingService($errorMsg, 0, \CBPTrackingType::Error);
1588 }
1589
1590 protected function getDebugInfo(array $values = [], array $map = []): array
1591 {
1592 if (count($map) <= 0)
1593 {
1594 $map = static::getPropertiesMap($this->getDocumentType());
1595 }
1596
1597 foreach ($map as $key => &$property)
1598 {
1599 if (is_string($property))
1600 {
1601 $property = [
1602 'Name' => $property,
1603 'Type' => 'string',
1604 ];
1605 }
1606
1607 if (!array_key_exists('TrackType', $property))
1608 {
1609 $property['TrackType'] = CBPTrackingType::Debug;
1610 }
1611
1612 if (array_key_exists('TrackValue', $property))
1613 {
1614 continue;
1615 }
1616
1617 if (!array_key_exists($key, $values))
1618 {
1619 $property['TrackValue'] = $this->__get($key);
1620
1621 continue;
1622 }
1623
1624 $property['TrackValue'] = $values[$key];
1625 }
1626
1627 return $map;
1628 }
1629
1630 protected function writeDebugInfo(array $map)
1631 {
1632 if (!$this->workflow->isDebug())
1633 {
1634 return;
1635 }
1636
1638 $documentService = $this->workflow->GetService("DocumentService");
1639
1640 foreach ($map as $property)
1641 {
1642 if (is_string($property))
1643 {
1644 $property = [
1645 'Name' => $property,
1646 'Type' => 'string',
1647 ];
1648 }
1649
1650 $fieldType = $documentService->getFieldTypeObject($this->getDocumentType(), $property);
1651 if (!$fieldType)
1652 {
1653 if (!array_key_exists('BaseType', $property))
1654 {
1655 continue;
1656 }
1657 $property['Type'] = $property['BaseType'];
1658 $fieldType = $documentService->getFieldTypeObject($this->getDocumentType(), $property);
1659
1660 if (!$fieldType)
1661 {
1662 continue;
1663 }
1664 }
1665
1666 $value = $fieldType->formatValue($property['TrackValue']);
1667 $value = ($value !== '') ? $value : '[]';
1668
1669 $this->writeDebugTrack(
1670 $this->getWorkflowInstanceId(),
1671 $this->getName(),
1672 $this->executionStatus,
1673 $this->executionResult,
1674 $this->getTitle(),
1675 $this->preparePropertyForWritingToTrack($value, $property['Name'] ?? ''),
1676 $property['TrackType'] ?? \CBPTrackingType::Debug
1677 );
1678 }
1679 }
1680
1681 public function getTitle(): string
1682 {
1683 $activityTitle = $this->isPropertyExists('Title') ? $this->Title : '';
1684
1685 if (is_string($activityTitle))
1686 {
1687 return $activityTitle;
1688 }
1689
1690 return '';
1691 }
1692
1693 public function setActivated(bool $activated): void
1694 {
1695 $this->activated = $activated;
1696 }
1697
1698 public function isActivated(): bool
1699 {
1700 return $this->activated;
1701 }
1702
1703 public static function validateProperties($arTestProperties = array(), CBPWorkflowTemplateUser $user = null)
1704 {
1705 return array();
1706 }
1707
1708 public static function validateChild($childActivity, $bFirstChild = false)
1709 {
1710 return array();
1711 }
1712
1713 public static function &findActivityInTemplate(&$arWorkflowTemplate, $activityName)
1714 {
1715 return CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
1716 }
1717
1718 public static function isExpression($text)
1719 {
1720 if (is_string($text))
1721 {
1722 $text = trim($text);
1723 if (
1724 preg_match(static::CalcPattern, $text)
1725 || preg_match(static::ValuePattern, $text)
1726 || preg_match(self::ValueSimplePattern, $text)
1727 )
1728 {
1729 return true;
1730 }
1731 }
1732
1733 return false;
1734 }
1735
1736 public static function parseExpression($exp): ?array
1737 {
1738 $matches = null;
1739 if (is_string($exp) && preg_match(static::ValuePattern, $exp, $matches))
1740 {
1741 $result = [
1742 'object' => $matches['object'],
1743 'field' => $matches['field'],
1744 'modifiers' => [],
1745 ];
1746 if (!empty($matches['mod1']))
1747 {
1748 $result['modifiers'][] = $matches['mod1'];
1749 }
1750 if (!empty($matches['mod2']))
1751 {
1752 $result['modifiers'][] = $matches['mod2'];
1753 }
1754
1755 return $result;
1756 }
1757 return null;
1758 }
1759
1760 protected function getStorage(): Bizproc\Storage\ActivityStorage
1761 {
1762 return $this->getStorageFactory()->getActivityStorage($this);
1763 }
1764
1765 private function getStorageFactory(): Bizproc\Storage\Factory
1766 {
1767 return Bizproc\Storage\Factory::getInstance();
1768 }
1769}
$arParams
Определения access_dialog.php:21
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const STRING
Определения fieldtype.php:57
static upsert(array $data)
Определения ResultTable.php:57
const Faulted
Определения constants.php:47
const Succeeded
Определения constants.php:45
const Canceled
Определения constants.php:46
const None
Определения constants.php:44
const Executing
Определения constants.php:8
const Canceling
Определения constants.php:9
const Faulting
Определения constants.php:11
const Initialized
Определения constants.php:7
const Closed
Определения constants.php:10
Определения activity.php:8
trackError(string $errorMsg)
Определения activity.php:1585
static includeActivityFile($code)
Определения activity.php:1348
initializeFromArray($arParams)
Определения activity.php:1409
getDebugInfo(array $values=[], array $map=[])
Определения activity.php:1590
getConstant($name)
Определения activity.php:355
static createInstance($code, $name)
Определения activity.php:1359
getWorkflowStatus()
Определения activity.php:97
setWorkflow(CBPWorkflow $workflow)
Определения activity.php:405
$workflow
Определения activity.php:41
execute()
Определения activity.php:1193
const FaultingEvent
Определения activity.php:22
removeStatusChangeHandler($event, $eventHandler)
Определения activity.php:1293
setFieldTypes(array $arFieldTypes=[])
Определения activity.php:107
setActivated(bool $activated)
Определения activity.php:1693
collectNestedActivities()
Определения activity.php:1073
getObjectSourceType($objectName, $fieldName)
Определения activity.php:1143
isActivated()
Определения activity.php:1698
static load($stream)
Определения activity.php:1227
setVariables($variables=[])
Определения activity.php:290
getStorage()
Определения activity.php:1760
getDocumentId()
Определения activity.php:52
static parseExpression($exp)
Определения activity.php:1736
setDocumentType(array $documentType)
Определения activity.php:84
array $arPropertiesTypes
Определения activity.php:36
setStatus($newStatus, $arEventParameters=array())
Определения activity.php:1318
isPropertyExists($name)
Определения activity.php:1068
getWorkflowTemplateId()
Определения activity.php:119
getConstantType($name)
Определения activity.php:363
getName()
Определения activity.php:384
const CancelingEvent
Определения activity.php:20
isVariableExists($name)
Определения activity.php:371
setPropertiesTypes($arPropertiesTypes=array())
Определения activity.php:225
setProperties($arProperties=array())
Определения activity.php:214
__construct($name)
Определения activity.php:1150
int $executionResult
Определения activity.php:14
toString()
Определения activity.php:1157
static & findActivityInTemplate(&$arWorkflowTemplate, $activityName)
Определения activity.php:1713
string $name
Определения activity.php:38
static checkResultViewRights(array $result, string $workflowId, int $userId)
Определения activity.php:1548
collectPropertyUsages($propertyName)
Определения activity.php:1085
bool $activated
Определения activity.php:39
cancel()
Определения activity.php:1204
static getPropertiesMap(array $documentType, array $context=[])
Определения activity.php:152
setVariable($name, $value)
Определения activity.php:317
pullProperties()
Определения activity.php:1052
const CalcPattern
Определения activity.php:32
getPropertyType($propertyName)
Определения activity.php:236
addStatusTitle($title='')
Определения activity.php:451
markCompleted($arEventParameters=[])
Определения activity.php:1439
array $arProperties
Определения activity.php:35
getDocumentEventType()
Определения activity.php:89
fixResult(Bitrix\Bizproc\Result\ResultDto $result)
Определения activity.php:1504
setDocumentId($documentId)
Определения activity.php:61
CBPActivity $parent
Определения activity.php:11
getVariableType($name)
Определения activity.php:335
getWorkflowInstanceId()
Определения activity.php:415
__isset($name)
Определения activity.php:1047
initialize()
Определения activity.php:1185
unsetWorkflow()
Определения activity.php:410
getTitle()
Определения activity.php:1681
int $executionStatus
Определения activity.php:13
const ValueInternalPattern
Определения activity.php:30
getRuntimeProperty($object, $field, CBPActivity $ownerActivity)
Определения activity.php:829
finalize()
Определения activity.php:1189
handleFault(Exception $exception)
Определения activity.php:1209
getACNames()
Определения activity.php:1237
getRootActivity()
Определения activity.php:389
getVariableBaseType($variableName)
Определения activity.php:284
static validateProperties($arTestProperties=array(), CBPWorkflowTemplateUser $user=null)
Определения activity.php:1703
static validateChild($childActivity, $bFirstChild=false)
Определения activity.php:1708
parseValue($value, $convertToType=null, ?callable $decorator=null)
Определения activity.php:1011
getRawProperty($name)
Определения activity.php:1018
array $arEventsMap
Определения activity.php:43
__set($name, $val)
Определения activity.php:1060
const ValuePattern
Определения activity.php:26
getPropertyBaseType($propertyName)
Определения activity.php:197
const ValueInlinePattern
Определения activity.php:28
__get($name)
Определения activity.php:1036
static callStaticMethod($code, $method, $arParameters=array())
Определения activity.php:1375
getVariable($name)
Определения activity.php:323
static checkUserAccessWithSubordination(int $userId, array $users)
Определения activity.php:1568
getTemplatePropertyType($propertyName)
Определения activity.php:203
const CalcInlinePattern
Определения activity.php:33
const ClosedEvent
Определения activity.php:21
setVariablesTypes($arVariablesTypes=array())
Определения activity.php:307
deleteStatusTitle($title='')
Определения activity.php:464
const StatusChangedEvent
Определения activity.php:18
static renderResult(array $result, string $workflowId, int $userId)
Определения activity.php:1522
fixUpParentChildRelationship(CBPActivity $nestedActivity)
Определения activity.php:1222
setWorkflowStatus($status)
Определения activity.php:102
getTemplateUserId()
Определения activity.php:134
markCanceled($arEventParameters=[])
Определения activity.php:1425
collectUsagesRecursive($val, &$usages)
Определения activity.php:1093
int $resultPriority
Определения activity.php:45
static isExpression($text)
Определения activity.php:1718
collectUsages()
Определения activity.php:1078
markFaulted($arEventParameters=[])
Определения activity.php:1445
reInitialize()
Определения activity.php:1198
const ExecutingEvent
Определения activity.php:19
addStatusChangeHandler($event, $eventHandler)
Определения activity.php:1282
const ReadDocument
Определения constants.php:216
static getDocumentFieldsAliasesMap($fields)
Определения document.php:1643
const PARAM_USED_DOCUMENT_FIELDS
Определения document.php:22
static getRuntime()
Определения runtime.php:80
const Error
Определения trackingservice.php:706
const Debug
Определения trackingservice.php:707
const CloseActivity
Определения trackingservice.php:699
const Custom
Определения trackingservice.php:702
Определения workflow.php:9
$children
Определения sync.php:12
$templateId
Определения component_props2.php:51
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$p
Определения group_list_element_edit.php:23
$activity
Определения options.php:214
$context
Определения csv_new_setup.php:223
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$status
Определения session.php:10
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$map
Определения config.php:5
Определения base.php:3
$value
Определения Param.php:39
getName()
Определения Param.php:99
$user
Определения mysql_to_pgsql.php:33
$GLOBALS['____1690880296']
Определения license.php:1
$message
Определения payment.php:8
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
$errorMsg
Определения refund.php:16
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
else $a
Определения template.php:137
$title
Определения pdf.php:123
$val
Определения options.php:1793
$method
Определения index.php:27
$matches
Определения index.php:22
$url
Определения iframe.php:7
$iterator
Определения yandex_run.php:610
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644