Template :: convertTemplate: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Engine\Template :: convertTemplate()
//  /dist/bitrix/modules/bizproc/lib/automation/engine/template.php:365

    
protected function convertTemplate()
    {
        
$this->robots = array();

        
$raw $this->template;
        if (!
is_array($raw) || !isset($raw['TEMPLATE']))
        {
            return 
false// BP template is lost.
        
}

        
/*if (!empty($raw['PARAMETERS']) || !empty($raw['VARIABLES']) || !empty($raw['CONSTANTS']))
        {
            $this->isExternalModified = true;
            return false; // modified or incorrect.
        }*/

        
if (empty($raw['TEMPLATE'][0]['Children']) || !is_array($raw['TEMPLATE'][0]['Children']))
            return 
true;

        if (
count($raw['TEMPLATE'][0]['Children']) > 1)
        {
            
$this->isExternalModified true;
            return 
false// modified or incorrect.
        
}

        
$parallelActivity $raw['TEMPLATE'][0]['Children'][0];
        if (!
$parallelActivity || $parallelActivity['Type'] !== static::$parallelActivityType)
        {
            
$this->isExternalModified true;
            return 
false// modified or incorrect.
        
}

        foreach (
$parallelActivity['Children'] as $sequence)
        {
            
$delay $condition null;
            
$robotsCnt 0;
            foreach (
$sequence['Children'] as $activity)
            {
                if (
$activity['Type'] === static::$delayActivityType)
                {
                    
$delay $activity;
                    continue;
                }

                if (
$activity['Type'] === static::$conditionActivityType)
                {
                    
$condition ConditionGroup::convertBizprocActivity($activity$this->getDocumentType());
                    if (
$condition === false)
                    {
                        
$this->isExternalModified true;
                        
$this->robots = array();
                        return 
false// modified or incorrect.
                    
}
                }

                if (!
$this->isRobot($activity))
                {
                    
$this->isExternalModified true;
                    
$this->robots = array();
                    return 
false// modified or incorrect.
                
}

                
$robotActivity = new Robot($activity);
                if (
$delay !== null)
                {
                    
$delayInterval DelayInterval::createFromActivityProperties($delay['Properties']);
                    
$robotActivity->setDelayInterval($delayInterval);
                    
$robotActivity->setDelayName($delay['Name']);
                    
$delay null;
                }

                if (
$condition !== null)
                {
                    
$robotActivity->setCondition($condition);
                    
$condition null;
                }

                if (
$robotsCnt 0)
                {
                    
$robotActivity->setExecuteAfterPrevious();
                }

                ++
$robotsCnt;
                
$this->robots[] = $robotActivity;
            }
        }

        return 
$this->robots;
    }