CBPWorkflowTemplateLoader :: ParseDocumentTypeStates: Bitrix method

      
<?php 
//  CBPWorkflowTemplateLoader :: ParseDocumentTypeStates()
//  /dist/bitrix/modules/bizproc/classes/general/workflowtemplateloader.php:411

    
private static function ParseDocumentTypeStates($arTemplatesListItem)
    {
        
$arWorkflowTemplate $arTemplatesListItem["TEMPLATE"];
        if (!
is_array($arWorkflowTemplate))
            throw new 
CBPArgumentTypeException("arTemplatesListItem");

        
$result = array(
            
"ID" => "",
            
"TEMPLATE_ID" => $arTemplatesListItem["ID"],
            
"TEMPLATE_NAME" => $arTemplatesListItem["NAME"],
            
"TEMPLATE_DESCRIPTION" => $arTemplatesListItem["DESCRIPTION"],
            
"STATE_NAME" => "",
            
"STATE_TITLE" => "",
            
"TEMPLATE_PARAMETERS" => $arTemplatesListItem["PARAMETERS"],
            
"STATE_PARAMETERS" => array(),
            
"STATE_PERMISSIONS" => array(),
            
"WORKFLOW_STATUS" => -1,
        );

        
$type "CBP".$arWorkflowTemplate[0]["Type"];
        
$bStateMachine false;
        while (
strlen($type) > 0)
        {
            if (
$type == "CBPStateMachineWorkflowActivity")
            {
                
$bStateMachine true;
                break;
            }
            
$type get_parent_class($type);
        }

        if (
$bStateMachine)
        {
            
//if (strlen($stateName) <= 0)
            
$stateName $arWorkflowTemplate[0]["Properties"]["InitialStateName"];

            if (
is_array($arWorkflowTemplate[0]["Children"]))
            {
                foreach (
$arWorkflowTemplate[0]["Children"] as $state)
                {
                    if (
$stateName == $state["Name"])
                    {
                        
$result["STATE_NAME"] = $stateName;
                        
$result["STATE_TITLE"] = $state["Properties"]["Title"];
                        
$result["STATE_PARAMETERS"] = array();
                        
$result["STATE_PERMISSIONS"] = $state["Properties"]["Permission"];

                        if (
is_array($state["Children"]))
                        {
                            foreach (
$state["Children"] as $event)
                            {
                                if (
$event["Type"] == "EventDrivenActivity")
                                {
                                    if (
$event["Children"][0]["Type"] == "HandleExternalEventActivity")
                                    {
                                        
$result["STATE_PARAMETERS"][] = array(
                                            
"NAME" => $event["Children"][0]["Name"],
                                            
"TITLE" => $event["Children"][0]["Properties"]["Title"],
                                            
"PERMISSION" => $event["Children"][0]["Properties"]["Permission"],
                                        );
                                    }
                                }
                            }
                        }

                        break;
                    }
                }
            }
        }
        else
        {
            
$result["STATE_PERMISSIONS"] = $arWorkflowTemplate[0]["Properties"]["Permission"];
        }

        if (
is_array($result["STATE_PERMISSIONS"]))
        {
            
$arKeys array_keys($result["STATE_PERMISSIONS"]);
            foreach (
$arKeys as $key)
            {
                
$ar self::ExtractValuesFromVariables($result["STATE_PERMISSIONS"][$key], $arTemplatesListItem["VARIABLES"], $arTemplatesListItem["CONSTANTS"]);
                
$result["STATE_PERMISSIONS"][$key] = CBPHelper::MakeArrayFlat($ar);
            }
        }

        return 
$result;
    }