9 use Bizproc\Debugger\Mixins\WriterDebugTrack;
16 private array $arStatusChangeHandlers = [];
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*\}';
26 public const ValuePattern =
'#^\s*'.self::ValueSinglePattern.
'\s*$#i';
27 private const ValueSimplePattern =
'#^\s*\{\{(.*?)\}\}\s*$#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*\}';
32 public const CalcPattern =
'#^\s*(=\s*(.*)|\{\{=\s*(.*)\s*\}\})\s*$#is';
69 public function getDocumentType()
72 if (empty($rootActivity->documentType))
75 $documentService = $this->workflow->getService(
'DocumentService');
76 $rootActivity->setDocumentType(
77 $documentService->getDocumentType($rootActivity->getDocumentId())
81 return $rootActivity->documentType;
91 return (
int)$this->
getRootActivity()->getRawProperty(CBPDocument::PARAM_DOCUMENT_EVENT_TYPE);
110 foreach ($arFieldTypes as
$key => $value)
112 $rootActivity->arFieldTypes[
$key] = $value;
123 if (method_exists($rootActivity,
'setWorkflowTemplateId'))
125 return $rootActivity->getWorkflowTemplateId();
139 if (method_exists($rootActivity,
'setTemplateUserId'))
141 $userId = $rootActivity->getTemplateUserId();
146 $userId = CBPWorkflowTemplateLoader::getTemplateUserId($tplId);
158 protected function clearProperties()
160 $rootActivity = $this->GetRootActivity();
161 $documentId = $rootActivity->GetDocumentId();
162 $documentType = $this->GetDocumentType();
164 $documentService = $this->workflow->GetService(
"DocumentService");
166 if (is_array($rootActivity->arPropertiesTypes) &&
count($rootActivity->arPropertiesTypes) > 0
167 && is_array($rootActivity->arFieldTypes) &&
count($rootActivity->arFieldTypes) > 0)
169 foreach ($rootActivity->arPropertiesTypes as
$key => $value)
171 if ($rootActivity->arFieldTypes[$value[
"Type"]][
"BaseType"] ==
"file")
173 foreach ((
array) $rootActivity->__get(
$key) as $v)
180 if ($file[
'MODULE_ID'] ===
'bizproc')
187 $fieldType = \Bitrix\Bizproc\FieldType::normalizeProperty($value);
188 if ($fieldTypeObject = $documentService->getFieldTypeObject($documentType, $fieldType))
190 $fieldTypeObject->setDocumentId($documentId)
191 ->clearValue($rootActivity->arProperties[
$key]);
199 $rootActivity = $this->GetRootActivity();
200 return $rootActivity->arFieldTypes[$rootActivity->arPropertiesTypes[$propertyName][
"Type"]][
"BaseType"];
205 $rootActivity = $this->GetRootActivity();
206 if ($propertyName ===
'TargetUser' && !isset($rootActivity->arPropertiesTypes[$propertyName]))
208 return [
'Type' =>
'user'];
211 return $rootActivity->arPropertiesTypes[$propertyName];
220 $this->arProperties[
$key] = $value;
231 $this->arPropertiesTypes[
$key] = $value;
238 return $this->arPropertiesTypes[$propertyName] ??
null;
242 protected function clearVariables()
244 $rootActivity = $this->GetRootActivity();
245 $documentId = $rootActivity->GetDocumentId();
246 $documentType = $this->GetDocumentType();
248 $documentService = $this->workflow->GetService(
"DocumentService");
250 if (is_array($rootActivity->arVariablesTypes) &&
count($rootActivity->arVariablesTypes) > 0
251 && is_array($rootActivity->arFieldTypes) &&
count($rootActivity->arFieldTypes) > 0)
253 foreach ($rootActivity->arVariablesTypes as
$key => $value)
256 isset($rootActivity->arFieldTypes[$value[
"Type"]])
257 && $rootActivity->arFieldTypes[$value[
"Type"]][
"BaseType"] ===
"file"
260 foreach ((
array) $rootActivity->arVariables[
$key] as $v)
267 if ($file[
'MODULE_ID'] ===
'bizproc')
274 $fieldType = \Bitrix\Bizproc\FieldType::normalizeProperty($value);
275 if ($fieldTypeObject = $documentService->getFieldTypeObject($documentType, $fieldType))
277 $fieldTypeObject->setDocumentId($documentId)
278 ->clearValue($rootActivity->arVariables[
$key]);
286 $rootActivity = $this->GetRootActivity();
287 return $rootActivity->arFieldTypes[$rootActivity->arVariablesTypes[$variableName][
"Type"]][
"BaseType"];
292 if (!is_array($variables))
297 if (
count($variables) > 0)
299 $rootActivity = $this->GetRootActivity();
300 foreach ($variables as
$key => $value)
302 $rootActivity->arVariables[
$key] = $value;
309 if (
count($arVariablesTypes) > 0)
311 $rootActivity = $this->GetRootActivity();
312 foreach ($arVariablesTypes as
$key => $value)
313 $rootActivity->arVariablesTypes[
$key] = $value;
319 $rootActivity = $this->GetRootActivity();
320 $rootActivity->arVariables[
$name] = $value;
325 $rootActivity = $this->GetRootActivity();
327 if (array_key_exists(
$name, $rootActivity->arVariables))
329 return $rootActivity->arVariables[
$name];
337 $rootActivity = $this->GetRootActivity();
338 return isset($rootActivity->arVariablesTypes[
$name]) ? $rootActivity->arVariablesTypes[
$name] :
null;
341 private function getConstantTypes()
343 $rootActivity = $this->GetRootActivity();
344 if (method_exists($rootActivity,
'GetWorkflowTemplateId'))
346 $templateId = $rootActivity->GetWorkflowTemplateId();
349 return CBPWorkflowTemplateLoader::getTemplateConstants(
$templateId);
357 $constants = $this->GetConstantTypes();
358 if (isset($constants[
$name][
'Default']))
359 return $constants[
$name][
'Default'];
365 $constants = $this->GetConstantTypes();
366 if (isset($constants[
$name]))
367 return $constants[
$name];
368 return array(
'Type' =>
null,
'Multiple' =>
false,
'Required' =>
false,
'Options' =>
null);
373 $rootActivity = $this->GetRootActivity();
374 $variables = $rootActivity->arVariables ?? [];
375 $variablesTypes = $rootActivity->arVariablesTypes ?? [];
378 array_key_exists(
$name, $variables)
379 || array_key_exists(
$name, $variablesTypes)
393 return $this->workflow->getRootActivity();
397 while (
$p->parent !==
null)
412 $this->workflow =
null;
417 return $this->workflow->GetInstanceId();
420 public function setStatusTitle(
$title =
'')
422 $rootActivity = $this->GetRootActivity();
423 $stateService = $this->workflow->GetService(
"StateService");
424 if ($rootActivity instanceof CBPStateMachineWorkflowActivity)
426 $arState = $stateService->GetWorkflowState($this->GetWorkflowInstanceId());
428 $arActivities = $rootActivity->CollectNestedActivities();
431 if (
$activity->GetName() == $arState[
"STATE_NAME"])
434 $stateService->SetStateTitle(
435 $this->GetWorkflowInstanceId(),
436 $activity->Title.($title !=
'' ?
": ".$title :
'')
443 $stateService->SetStateTitle(
444 $this->GetWorkflowInstanceId(),
456 $stateService = $this->workflow->GetService(
"StateService");
458 $mainTitle = $stateService->GetStateTitle($this->GetWorkflowInstanceId());
459 $mainTitle .= ((mb_strpos($mainTitle,
": ") !==
false) ?
", " :
": ").
$title;
461 $stateService->SetStateTitle($this->GetWorkflowInstanceId(), $mainTitle);
469 $stateService = $this->workflow->GetService(
"StateService");
470 $mainTitle = $stateService->GetStateTitle($this->GetWorkflowInstanceId());
472 $ar1 = explode(
":", $mainTitle);
473 if (
count($ar1) <= 1)
478 $ar2 = explode(
",", $ar1[1]);
490 $result = $ar1[0].($newTitle <>
'' ?
": " :
"").$newTitle;
492 $stateService->SetStateTitle($this->GetWorkflowInstanceId(),
$result);
495 private function getPropertyValueRecursive(
$val, $convertToType =
null, ?callable $decorator =
null)
502 $parsed = static::parseExpression(
$val);
507 $parsed[
'modifiers'][] = $convertToType;
508 $this->getRealParameterValue(
512 $parsed[
'modifiers'],
522 $keys = array_keys(
$val);
525 foreach ($keys as
$key)
535 foreach ($keys as
$key)
537 [$t,
$a] = $this->GetPropertyValueRecursive(
$val[
$key], $convertToType, $decorator);
540 if ($t == 1 && is_array(
$a))
541 $r = array_merge($r,
$a);
553 $keys = array_keys($r);
554 if ($keys[0] == 0 && $keys[1] == 1 && is_string($r[0]) && is_string($r[1]))
557 $modifiers = $convertToType ?
array($convertToType) :
array();
558 if ($this->GetRealParameterValue($r[0], $r[1],
$result, $modifiers, $decorator))
569 $fieldTypeObject =
null;
573 $documentService = $this->workflow->GetService(
"DocumentService");
574 $documentType = $this->GetDocumentType();
576 $typesMap = $documentService->getTypesMap($documentType);
577 $convertToType = mb_strtolower($convertToType);
578 if (isset($typesMap[$convertToType]))
580 $typeClass = $typesMap[$convertToType];
581 $fieldTypeObject = $documentService->getFieldTypeObject(
583 array(
'Type' => \Bitrix\Bizproc\FieldType::STRING)
588 $calc =
new Bizproc\Calc\Parser($this);
589 if (preg_match(self::CalcPattern,
$val))
591 $r = $calc->Calculate(
$val);
594 if ($typeClass && $fieldTypeObject)
597 $fieldTypeObject->setMultiple(
true);
598 $r = $fieldTypeObject->convertValue($r, $typeClass);
600 return array(is_array($r)? 1 : 2, $r);
605 $val = preg_replace_callback(
606 static::CalcInlinePattern,
611 $r = implode(
', ', CBPHelper::MakeArrayFlat($r));
612 return $r !==
null? $r.$matches[2] :
$matches[0];
618 $val = preg_replace_callback(
619 static::ValueInlinePattern,
620 fn(
$matches) => $this->parseStringParameter(
$matches, $convertToType, $decorator),
625 if ($typeClass && $fieldTypeObject)
627 $val = $fieldTypeObject->convertValue(
$val, $typeClass);
635 private function getRealParameterValue(
639 array $modifiers =
null,
640 ?callable $decorator =
null
646 $documentService = $this->workflow->GetService(
"DocumentService");
648 if ($objectName ===
"Document")
650 $rootActivity = $this->GetRootActivity();
651 $documentId = $rootActivity->GetDocumentId();
653 $documentType = $this->GetDocumentType();
655 $document = $documentService->GetDocument($documentId, $documentType, $usedDocumentFields);
656 $documentFields = $documentService->GetDocumentFields($documentType);
659 if (!isset($document[$fieldName]) && mb_strtoupper(mb_substr($fieldName, -10)) ===
'_PRINTABLE')
661 $fieldName = mb_substr($fieldName, 0, -10);
662 if (!in_array(
'printable', $modifiers))
664 $modifiers[] =
'printable';
667 if (!isset($document[$fieldName]) && isset($documentFieldsAliasesMap[$fieldName]))
669 $fieldName = $documentFieldsAliasesMap[$fieldName];
674 if (isset($document[$fieldName]))
676 $result = $document[$fieldName];
677 if (is_array(
$result) && mb_strtoupper(mb_substr($fieldName, -10)) ===
'_PRINTABLE')
682 $property = isset($documentFields[$fieldName]) ? $documentFields[$fieldName] :
null;
685 elseif (in_array($objectName, [
'Template',
'Variable',
'Constant']))
687 $rootActivity = $this->GetRootActivity();
689 if (mb_substr($fieldName, -10) ==
"_printable")
691 $fieldName = mb_substr($fieldName, 0, -10);
692 $modifiers = [
'printable'];
698 $result = $rootActivity->GetVariable($fieldName);
699 $property = $rootActivity->getVariableType($fieldName);
702 $result = $rootActivity->GetConstant($fieldName);
703 $property = $rootActivity->GetConstantType($fieldName);
706 $result = $rootActivity->__get($fieldName);
707 $property = $rootActivity->getTemplatePropertyType($fieldName);
710 elseif ($objectName ===
'GlobalConst')
712 $property = Bizproc\Workflow\Type\GlobalConst::getById($fieldName);
713 if (!$property && mb_substr($fieldName, -10) ==
"_printable")
715 $fieldName = mb_substr($fieldName, 0, -10);
716 $modifiers = [
'printable'];
717 $property = Bizproc\Workflow\Type\GlobalConst::getById($fieldName);
720 $result = Bizproc\Workflow\Type\GlobalConst::getValue($fieldName);
722 elseif ($objectName ===
'GlobalVar')
724 $property = Bizproc\Workflow\Type\GlobalVar::getById($fieldName);
725 if (!$property && mb_substr($fieldName, -10) ==
"_printable")
727 $fieldName = mb_substr($fieldName, 0, -10);
728 $modifiers = [
'printable'];
729 $property = Bizproc\Workflow\Type\GlobalVar::getById($fieldName);
732 $result = Bizproc\Workflow\Type\GlobalVar::getValue($fieldName);
734 elseif ($objectName ===
"Workflow")
736 $result = $this->GetWorkflowInstanceId();
737 $property =
array(
'Type' =>
'string');
739 elseif ($objectName ===
"User")
741 if (mb_substr($fieldName, -10) ==
"_printable")
743 $modifiers = [
'printable'];
749 $result =
"user_".$GLOBALS[
"USER"]->GetID();
751 $property =
array(
'Type' =>
'user');
753 elseif ($objectName ===
"System")
755 if (mb_substr($fieldName, -10) ===
"_printable")
757 $fieldName = mb_substr($fieldName, 0, -10);
758 $modifiers = [
'printable'];
762 $property =
array(
'Type' =>
'datetime');
763 $systemField = mb_strtolower($fieldName);
764 if ($systemField ===
'now')
766 $result =
new Bizproc\BaseType\Value\DateTime();
768 elseif ($systemField ===
'nowlocal')
770 $result =
new Bizproc\BaseType\Value\DateTime(time(), CTimeZone::GetOffset());
772 elseif ($systemField ===
'date')
774 $result =
new Bizproc\BaseType\Value\Date();
775 $property =
array(
'Type' =>
'date');
777 elseif ($systemField ===
'eol')
780 $property = [
'Type' =>
'string'];
782 elseif ($systemField ===
'hosturl')
784 $result = Main\Engine\UrlManager::getInstance()->getHostUrl();
785 $property = [
'Type' =>
'string'];
795 $activity = $this->workflow->GetActivityByName($objectName);
799 $property =
$activity->getPropertyType($fieldName);
809 $fieldTypeObject = $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
810 if ($fieldTypeObject)
812 $fieldTypeObject->setDocumentId($this->GetDocumentId());
813 $result = $fieldTypeObject->internalizeValue($objectName,
$result);
819 $result = $this->applyPropertyValueModifiers($fieldName, $property,
$result, $modifiers);
823 $result = $decorator($objectName, $fieldName, $property,
$result);
832 $documentType = $rootActivity->getDocumentType();
833 $usedDocumentFields = $rootActivity->{CBPDocument::PARAM_USED_DOCUMENT_FIELDS} ?? [];
838 if (CBPHelper::isEmptyValue($object))
844 $result = $rootActivity->__get($field);
845 $property = $rootActivity->getTemplatePropertyType($field);
849 $result = $rootActivity->getVariable($field);
850 $property = $rootActivity->getVariableType($field);
854 $result = $rootActivity->getConstant($field);
855 $property = $rootActivity->getConstantType($field);
859 $result = Bizproc\Workflow\Type\GlobalConst::getValue($field);
860 $property = Bizproc\Workflow\Type\GlobalConst::getVisibleById($field, $documentType);
864 $result = Bizproc\Workflow\Type\GlobalVar::getValue($field);
865 $property = Bizproc\Workflow\Type\GlobalVar::getVisibleById($field, $documentType);
870 $documentFields = $documentService->GetDocumentFields($documentType);
871 $documentId = $rootActivity->getDocumentId();
872 $property = $documentFields[$field] ??
null;
873 $result = $documentService->getFieldValue($documentId, $field, $documentType, $usedDocumentFields);
877 $activity = $rootActivity->workflow->getActivityByName($object);
881 $property =
$activity->getPropertyType($field);
887 $property = [
'Type' =>
'string'];
893 private function applyPropertyValueModifiers($fieldName, $property, $value,
array $modifiers)
895 if (empty($property) || empty($modifiers) || !is_array($property))
901 $modifiers = array_slice($modifiers, 0, 2);
903 $rootActivity = $this->GetRootActivity();
904 $documentId = $rootActivity->GetDocumentId();
906 $documentService = $this->workflow->GetService(
"DocumentService");
907 $documentType = $this->GetDocumentType();
909 $typesMap = $documentService->getTypesMap($documentType);
910 foreach ($modifiers as $m)
912 $m = mb_strtolower($m);
913 if (isset($typesMap[$m]))
916 $typeClass ??= $typesMap[$m];
924 $priority = $format && array_search($format, $modifiers) === 0 ?
'format' :
'type';
926 if ($typeName === \
Bitrix\
Bizproc\FieldType::STRING && $format ===
'printable')
931 if ($typeClass || $format)
933 $fieldTypeObject = $documentService->getFieldTypeObject($documentType, $property);
935 if ($fieldTypeObject)
937 $fieldTypeObject->setDocumentId($documentId);
939 if ($format && $priority ===
'format')
941 $value = $fieldTypeObject->formatValue($value, $format);
948 $value = $fieldTypeObject->convertValue($value, $typeClass);
951 if ($format && $priority !==
'format')
953 $value = $fieldTypeObject->formatValue($value, $format);
956 elseif ($format ==
'printable')
958 $value = $documentService->GetFieldValuePrintable(
966 if (is_array($value))
967 $value = implode(
", ", CBPHelper::MakeArrayFlat($value));
974 private function parseStringParameter(
$matches, $convertToType =
null, ?callable $decorator =
null)
988 $modifiers[] = $convertToType;
991 if (empty($modifiers))
1011 public function parseValue($value, $convertToType =
null, ?callable $decorator =
null)
1013 [$t, $r] = $this->getPropertyValueRecursive($value, $convertToType, $decorator);
1020 if (isset($this->arProperties[
$name]))
1022 return $this->arProperties[
$name];
1039 if ($property !==
null)
1041 [$t, $r] = $this->GetPropertyValueRecursive($property);
1055 $this->arProperties = array_fill_keys(array_keys($this->arProperties),
null);
1062 if (array_key_exists(
$name, $this->arProperties))
1070 return array_key_exists(
$name, $this->arProperties);
1097 foreach (
$val as $v)
1104 $parsed = static::parseExpression(
$val);
1131 $val = preg_replace_callback(
1132 static::ValueInlinePattern,
1145 return \Bitrix\Bizproc\Workflow\Template\SourceType::getObjectSourceType($objectName, $fieldName);
1152 $this->name =
$name;
1160 " [".get_class($this).
"] (status=".
1161 CBPActivityExecutionStatus::Out($this->executionStatus).
1163 CBPActivityExecutionResult::Out($this->executionResult).
1164 ", count(ClosedEvent)=".
1165 count($this->arStatusChangeHandlers[self::ClosedEvent]).
1169 public function dump($level = 3)
1171 $result = str_repeat(
" ", $level).$this->ToString().
"\n";
1173 if (is_subclass_of($this,
"CBPCompositeActivity"))
1176 foreach ($this->arActivities as
$activity)
1224 $nestedActivity->parent = $this;
1227 public static function load($stream)
1234 return CBPRuntime::GetRuntime()->unserializeWorkflowStream($stream);
1239 return array(mb_substr(get_class($this), 3));
1245 foreach ($arT as $t)
1247 if (!in_array($t, $arUsedActivities))
1249 $arUsedActivities[] = $t;
1253 if ($arNestedActivities =
$activity->CollectNestedActivities())
1255 foreach ($arNestedActivities as $nestedActivity)
1257 self::SearchUsedActivities($nestedActivity, $arUsedActivities);
1262 public function save()
1264 $usedActivities = [];
1265 self::SearchUsedActivities($this, $usedActivities);
1267 if (
$children = $this->collectNestedActivities())
1272 $child->unsetWorkflow();
1276 $strUsedActivities = implode(
",", $usedActivities);
1277 return $strUsedActivities.
";".serialize($this);
1284 if (!is_array($this->arStatusChangeHandlers))
1285 $this->arStatusChangeHandlers =
array();
1287 if (!array_key_exists(
$event, $this->arStatusChangeHandlers))
1290 $this->arStatusChangeHandlers[
$event][] = $eventHandler;
1295 if (!is_array($this->arStatusChangeHandlers))
1296 $this->arStatusChangeHandlers =
array();
1298 if (!array_key_exists(
$event, $this->arStatusChangeHandlers))
1301 $index = array_search($eventHandler, $this->arStatusChangeHandlers[
$event],
true);
1303 if ($index !==
false)
1304 unset($this->arStatusChangeHandlers[
$event][$index]);
1309 private function fireStatusChangedEvents(
$event, $arEventParameters =
array())
1311 if (array_key_exists(
$event, $this->arStatusChangeHandlers) && is_array($this->arStatusChangeHandlers[
$event]))
1313 foreach ($this->arStatusChangeHandlers[
$event] as $eventHandler)
1314 call_user_func_array(
array($eventHandler,
"OnEvent"),
array($this, $arEventParameters));
1320 $this->executionStatus = $newStatus;
1321 $this->fireStatusChangedEvents(self::StatusChangedEvent, $arEventParameters);
1326 $this->fireStatusChangedEvents(self::ExecutingEvent, $arEventParameters);
1330 $this->fireStatusChangedEvents(self::CancelingEvent, $arEventParameters);
1334 $this->fireStatusChangedEvents(self::ClosedEvent, $arEventParameters);
1338 $this->fireStatusChangedEvents(self::FaultingEvent, $arEventParameters);
1350 return CBPRuntime::getRuntime()->includeActivityFile(
$code);
1361 if (preg_match(
"#[^a-zA-Z0-9_]#",
$code))
1366 $classname =
'CBP' .
$code;
1367 if (class_exists($classname))
1369 return new $classname(
$name);
1377 $runtime = CBPRuntime::GetRuntime();
1378 if (!$runtime->IncludeActivityFile(
$code))
1382 "code" =>
"ActivityNotFound",
1383 "parameter" =>
$code,
1389 if (preg_match(
"#[^a-zA-Z0-9_]#",
$code))
1394 if (strpos(
$code,
'CBP') === 0)
1399 $classname =
'CBP'.$code;
1401 if (method_exists($classname,
$method))
1403 return call_user_func_array(
array($classname,
$method), $arParameters);
1415 if (array_key_exists(
$key, $this->arProperties))
1417 $this->arProperties[
$key] = $value;
1435 $this->markClosed($arEventParameters);
1442 $this->markClosed($arEventParameters);
1448 $this->markClosed($arEventParameters);
1451 private function markClosed($arEventParameters = [])
1453 switch ($this->executionStatus)
1461 foreach ($this->arActivities as
$activity)
1473 if ($this->isActivated())
1476 $trackingService = $this->workflow->getService(
'TrackingService');
1477 $trackingService->write(
1478 $this->getWorkflowInstanceId(),
1481 $this->executionStatus,
1482 $this->executionResult,
1495 protected function writeToTrackingService(
$message =
"", $modifiedBy = 0, $trackingType = -1)
1498 $trackingService = $this->workflow->GetService(
"TrackingService");
1499 if ($trackingType < 0)
1501 $trackingService->Write($this->GetWorkflowInstanceId(), $trackingType, $this->name, $this->executionStatus, $this->executionResult, ($this->IsPropertyExists(
"Title") ? $this->Title :
""),
$message, $modifiedBy);
1510 'WORKFLOW_ID' => $workflowId,
1511 'PRIORITY' => $this->resultPriority,
1512 'ACTIVITY' =>
$result->activity,
1516 catch (Throwable $e)
1527 return RenderedResult::makeNoRights();
1530 $documentService = CBPRuntime::getRuntime()->getDocumentService();
1532 if (isset(
$result[
'DOCUMENT_ID']))
1534 $url = $documentService->getDocumentDetailUrl(
$result[
'DOCUMENT_ID']);
1535 $name = $documentService->getDocumentName(
$result[
'DOCUMENT_ID']);
1536 if (isset(
$result[
'DOCUMENT_TYPE']))
1538 $type = (string)$documentService->getDocumentTypeCaption(
$result[
'DOCUMENT_TYPE']);
1545 return RenderedResult::makeNoResult();
1550 $currentUser = new \CBPWorkflowTemplateUser(
$userId);
1551 $userCanReadDocument =
false;
1553 if (isset(
$result[
'DOCUMENT_ID']))
1555 $userCanReadDocument = \CBPDocument::canUserOperateDocument(
1557 $currentUser->getId(),
1563 $currentUser->isAdmin()
1564 || self::checkUserAccessWithSubordination($currentUser->getId(),
$result[
'USERS'] ?? [])
1565 || $userCanReadDocument;
1570 if (in_array(
$userId, $users,
true))
1574 foreach ($users as
$user)
1576 if (\CBPHelper::checkUserSubordination(
$userId,
$user))
1594 $map = static::getPropertiesMap($this->getDocumentType());
1597 foreach (
$map as
$key => &$property)
1599 if (is_string($property))
1602 'Name' => $property,
1607 if (!array_key_exists(
'TrackType', $property))
1612 if (array_key_exists(
'TrackValue', $property))
1617 if (!array_key_exists(
$key, $values))
1619 $property[
'TrackValue'] = $this->
__get(
$key);
1624 $property[
'TrackValue'] = $values[
$key];
1630 protected function writeDebugInfo(
array $map)
1632 if (!$this->workflow->isDebug())
1638 $documentService = $this->workflow->GetService(
"DocumentService");
1640 foreach (
$map as $property)
1642 if (is_string($property))
1645 'Name' => $property,
1650 $fieldType = $documentService->getFieldTypeObject($this->getDocumentType(), $property);
1653 if (!array_key_exists(
'BaseType', $property))
1657 $property[
'Type'] = $property[
'BaseType'];
1658 $fieldType = $documentService->getFieldTypeObject($this->getDocumentType(), $property);
1666 $value = $fieldType->formatValue($property[
'TrackValue']);
1669 $this->writeDebugTrack(
1670 $this->getWorkflowInstanceId(),
1672 $this->executionStatus,
1673 $this->executionResult,
1675 $this->preparePropertyForWritingToTrack($value, $property[
'Name'] ??
''),
1685 if (is_string($activityTitle))
1687 return $activityTitle;
1700 return $this->activated;
1715 return CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName);
1720 if (is_string(
$text))
1724 preg_match(static::CalcPattern,
$text)
1725 || preg_match(static::ValuePattern,
$text)
1726 || preg_match(self::ValueSimplePattern,
$text)
1739 if (is_string($exp) && preg_match(static::ValuePattern, $exp,
$matches))
1762 return $this->getStorageFactory()->getActivityStorage($this);
1767 return Bizproc\Storage\Factory::getInstance();