CBPWorkflow::initialize

  1. Bitrix24 API (v. 23.675.0)
  2. bizproc
  3. CBPWorkflow
  4. initialize
  • Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/classes/general/workflow.php
  • Класс: CBPWorkflow
  • Вызов: CBPWorkflow::initialize
public function initialize(
	CBPActivity $rootActivity,
	$documentId,
	$workflowParameters = [],
	$workflowVariablesTypes = [],
	$workflowParametersTypes = [],
	$workflowTemplateId = 0
)
{
	$this->rootActivity = $rootActivity;
	$rootActivity->SetWorkflow($this);
	if (method_exists($rootActivity, 'SetWorkflowTemplateId'))
	{
		$rootActivity->SetWorkflowTemplateId($workflowTemplateId);
	}

	if (method_exists($rootActivity, 'setTemplateUserId'))
	{
		$rootActivity->setTemplateUserId(
			CBPWorkflowTemplateLoader::getTemplateUserId($workflowTemplateId)
		);
	}

	$arDocumentId = CBPHelper::ParseDocumentId($documentId);

	$rootActivity->SetDocumentId($arDocumentId);

	$documentService = $this->GetService("DocumentService");
	$documentType = $workflowParameters[CBPDocument::PARAM_DOCUMENT_TYPE]
		?? $documentService->GetDocumentType($arDocumentId)
	;

	unset($workflowParameters[CBPDocument::PARAM_DOCUMENT_TYPE]);

	if ($documentType !== null)
	{
		$rootActivity->SetDocumentType($documentType);
		$rootActivity->SetFieldTypes($documentService->GetDocumentFieldTypes($documentType));
	}

	$rootActivity->SetProperties($workflowParameters);

	$rootActivity->SetVariablesTypes($workflowVariablesTypes);
	if (is_array($workflowVariablesTypes))
	{
		foreach ($workflowVariablesTypes as $k => $v)
		{
			$variableValue = $v["Default"] ?? null;
			if ($documentType && $fieldTypeObject = $documentService->getFieldTypeObject($documentType, $v))
			{
				$fieldTypeObject->setDocumentId($arDocumentId);
				$variableValue = $fieldTypeObject->internalizeValue('Variable', $variableValue);
			}

			//set defaults on start
			$rootActivity->SetVariable($k, $variableValue);
		}
	}

	$rootActivity->SetPropertiesTypes($workflowParametersTypes);
}

Добавить комментарий