CBPDocument :: getTemplatesForStart: Bitrix method

      
<?php 
//  CBPDocument :: getTemplatesForStart()
//  /dist/bitrix/modules/bizproc/classes/general/document.php:1625

    
public static function getTemplatesForStart($userId$documentType$documentId null, array $parameters = array())
    {
        if (!isset(
$parameters['UserGroups']))
        {
            
$parameters['UserGroups'] = CUser::GetUserGroup($userId);
        }
        if (!isset(
$parameters['DocumentStates']))
        {
            
$parameters['DocumentStates'] = static::GetDocumentStates($documentType$documentId);
        }
        
$op CBPCanUserOperateOperation::StartWorkflow;

        
$templates = array();
        
$dbWorkflowTemplate CBPWorkflowTemplateLoader::GetList(
            array(),
            array(
                
"DOCUMENT_TYPE" => $documentType,
                
"ACTIVE" => "Y",
                
'<AUTO_EXECUTE' => CBPDocumentEventType::Automation
            
),
            
false,
            
false,
            array(
"ID""NAME""DESCRIPTION""PARAMETERS")
        );
        while (
$arWorkflowTemplate $dbWorkflowTemplate->fetch())
        {
            
$parameters['WorkflowTemplateId'] = $arWorkflowTemplate['ID'];
            if (
$documentId)
            {
                if (!
CBPDocument::CanUserOperateDocument($op$userId$documentId$parameters))
                {
                    continue;
                }
            }
            elseif (!
CBPDocument::CanUserOperateDocumentType($op$userId$documentType$parameters))
            {
                continue;
            }

            
$templates[] = array(
                
'id' => $arWorkflowTemplate['ID'],
                
'name' => $arWorkflowTemplate['NAME'],
                
'description' => $arWorkflowTemplate['DESCRIPTION'],
                
'hasParameters' => count($arWorkflowTemplate['PARAMETERS']) > 0,
                
'isConstantsTuned' => CBPWorkflowTemplateLoader::isConstantsTuned($arWorkflowTemplate["ID"])
            );
        }

        return 
$templates;
    }