CBPDocument :: AddDefaultWorkflowTemplates: Bitrix method

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

    
public static function AddDefaultWorkflowTemplates($documentType$additionalModuleId null)
    {
        if (!empty(
$additionalModuleId))
        {
            
$additionalModuleId preg_replace("/[^a-z0-9_.]/i"""$additionalModuleId);
            
$arModule = array($additionalModuleId$documentType[0], 'bizproc');
        }
        else
        {
            
$arModule = array($documentType[0], 'bizproc');
        }

        
$bIn false;
        foreach (
$arModule as $sModule)
        {
            if (
file_exists($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
            {
                if(
$handle opendir($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates'))
                {
                    
$bIn true;
                    while(
false !== ($file readdir($handle)))
                    {
                        if(!
is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file))
                            continue;
                        
$arFields false;
                        include(
$_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$sModule.'/templates/'.$file);
                        if(
is_array($arFields))
                        {
                            
/*
                             * If DOCUMENT_TYPE not defined, use current documentType
                             * Overwise check if DOCUMENT_TYPE equals to current documentType
                             */
                            
if (!array_key_exists("DOCUMENT_TYPE"$arFields))
                                
$arFields["DOCUMENT_TYPE"] = $documentType;
                            elseif(
$arFields["DOCUMENT_TYPE"] != $documentType)
                                continue;

                            
$arFields["SYSTEM_CODE"] = $file;
                            if(
is_object($GLOBALS['USER']))
                                
$arFields["USER_ID"] = $GLOBALS['USER']->GetID();
                            
$arFields["MODIFIER_USER"] = new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser);
                            try
                            {
                                
CBPWorkflowTemplateLoader::Add($arFields);
                            }
                            catch (
Exception $e)
                            {
                            }
                        }
                    }
                    
closedir($handle);
                }
            }
            if (
$bIn)
                break;
        }
    }