CBPWorkflowTemplateLoader :: ParseFields: Bitrix method

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

    
protected function ParseFields(&$arFields$id 0$systemImport false)
    {
        
$id intval($id);
        
$updateMode = ($id true false);
        
$addMode = !$updateMode;

        if (
$addMode && !is_set($arFields"DOCUMENT_TYPE"))
            throw new 
CBPArgumentNullException("DOCUMENT_TYPE");

        if (
is_set($arFields"DOCUMENT_TYPE"))
        {
            
$arDocumentType CBPHelper::ParseDocumentId($arFields["DOCUMENT_TYPE"]);

            
$arFields["MODULE_ID"] = $arDocumentType[0];
            
$arFields["ENTITY"] = $arDocumentType[1];
            
$arFields["DOCUMENT_TYPE"] = $arDocumentType[2];
        }
        else
        {
            unset(
$arFields["MODULE_ID"]);
            unset(
$arFields["ENTITY"]);
            unset(
$arFields["DOCUMENT_TYPE"]);
        }

        if (
is_set($arFields"NAME") || $addMode)
        {
            
$arFields["NAME"] = trim($arFields["NAME"]);
            if (
strlen($arFields["NAME"]) <= 0)
                throw new 
CBPArgumentNullException("NAME");
        }

        if (
$addMode && !is_set($arFields"TEMPLATE"))
            throw new 
CBPArgumentNullException("TEMPLATE");

        if (
is_set($arFields"TEMPLATE"))
        {
            if (!
is_array($arFields["TEMPLATE"]))
            {
                throw new 
CBPArgumentTypeException("TEMPLATE""array");
            }
            else
            {
                
$userTmp null;

                if (!
$systemImport)
                {
                    if (
array_key_exists("MODIFIER_USER"$arFields))
                    {
                        if (
is_object($arFields["MODIFIER_USER"]) && is_a($arFields["MODIFIER_USER"], "CBPWorkflowTemplateUser"))
                            
$userTmp $arFields["MODIFIER_USER"];
                        else
                            
$userTmp = new CBPWorkflowTemplateUser($arFields["MODIFIER_USER"]);
                    }
                    else
                    {
                        
$userTmp = new CBPWorkflowTemplateUser();
                    }

                    
$errors = array();
                    foreach (
$arFields["TEMPLATE"] as $v)
                        
$errors array_merge($errors$this->ValidateTemplate($v$userTmp));

                    if (
count($errors) > 0)
                    {
                        
$messages = array();
                        foreach (
$errors as $v)
                        {
                            
$messages[] = trim($v["message"]);
                        }
                        throw new 
CBPWorkflowTemplateValidationException(implode('.'$messages), $errors);
                    }
                }

                
$arFields["TEMPLATE"] = $this->GetSerializedForm($arFields["TEMPLATE"]);
            }
        }

        foreach (array(
'PARAMETERS''VARIABLES''CONSTANTS') as $field)
        {
            if (
is_set($arFields$field))
            {
                if (
$arFields[$field] == null)
                {
                    
$arFields[$field] = false;
                }
                elseif (
is_array($arFields[$field]))
                {
                    if (
count($arFields[$field]) > 0)
                        
$arFields[$field] = $this->GetSerializedForm($arFields[$field]);
                    else
                        
$arFields[$field] = false;
                }
                else
                {
                    throw new 
CBPArgumentTypeException($field);
                }
            }
        }

        if(
is_set($arFields"ACTIVE") && $arFields["ACTIVE"] != 'N')
            
$arFields["ACTIVE"] = 'Y';

        if(
is_set($arFields"IS_MODIFIED") && $arFields["IS_MODIFIED"] != 'N')
            
$arFields["IS_MODIFIED"] = 'Y';

        unset(
$arFields["MODIFIED"]);
    }