CBPWorkflow::Initialize: Bitrix method

      
<?php 
//  CBPWorkflow :: Initialize()
//  /dist/bitrix/modules/bizproc/classes/general/workflow.php:89

    
public function Initialize(CBPActivity $rootActivity$documentId$workflowParameters = array(), $workflowVariablesTypes = array(), $workflowParametersTypes = array(), $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 = isset($workflowParameters[CBPDocument::PARAM_DOCUMENT_TYPE]) ?
            
$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"];
                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);
    }