ConditionGroup :: evaluate: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Engine\ConditionGroup :: evaluate()
//  /dist/bitrix/modules/bizproc/lib/automation/engine/conditiongroup.php:48

    
public function evaluate(BaseTarget $target)
    {
        if (empty(
$this->items))
        {
            return 
true;
        }

        
$documentType $target->getDocumentType();
        
$documentId $documentType;
        
$documentId[2] = $target->getDocumentId();

        
$documentService = \CBPRuntime::getRuntime(true)->getDocumentService();
        
$document $documentService->getDocument($documentId$documentType);
        
$documentFields $documentService->getDocumentFields($documentType);

        
$result = array(=> true);
        
$i 0;
        
$joiner = static::JOINER_AND;

        foreach (
$this->items as $item)
        {
            
/** @var Condition $condition */
            
$condition $item[0];
            
$conditionField $condition->getField();

            
$conditionResult true;

            if (
array_key_exists($conditionField$document))
            {
                
$fld $document[$conditionField];
                
$type null;
                
$fieldType null;

                if (isset(
$documentFields[$conditionField]))
                {
                    
$type $documentFields[$conditionField]["BaseType"];
                    if (
$documentFields[$conditionField]['Type'] === 'UF:boolean')
                    {
                        
$type 'bool';
                    }
                    
$fieldType $documentService->getFieldTypeObject($documentType$documentFields[$conditionField]);
                }

                if (!
$condition->check($fld$type$target$fieldType))
                {
                    
$conditionResult false;
                }
            }

            if (
$joiner == static::JOINER_OR)
            {
                ++
$i;
                
$result[$i] = $conditionResult;
            }
            elseif (!
$conditionResult)
            {
                
$result[$i] = false;
            }
            
$joiner = ($item[1] === static::JOINER_OR) ? static::JOINER_OR : static::JOINER_AND;
        }

        return (
count(array_filter($result)) > 0);
    }