GetRealParameterValue: Bitrix method

      
<?php 
//  GetRealParameterValue()
//  /dist/bitrix/modules/bizproc/classes/general/activity.php:559

    
private function GetRealParameterValue($objectName$fieldName, &$result, array $modifiers null)
    {
        
$return true;
        
$property null;
        
/** @var CBPDocumentService $documentService */
        
$documentService $this->workflow->GetService("DocumentService");

        if (
$objectName == "Document")
        {
            
$rootActivity $this->GetRootActivity();
            
$documentId $rootActivity->GetDocumentId();

            
$documentType $this->GetDocumentType();
            
$document $documentService->GetDocument($documentId$documentType);
            
$documentFields $documentService->GetDocumentFields($documentType);
            
//check aliases
            
$documentFieldsAliasesMap CBPDocument::getDocumentFieldsAliasesMap($documentFields);
            if (!isset(
$document[$fieldName]) && strtoupper(substr($fieldName, -strlen('_PRINTABLE'))) == '_PRINTABLE')
            {
                
$fieldName substr($fieldName0, -strlen('_PRINTABLE'));
                if (!
in_array('printable'$modifiers))
                    
$modifiers[] = 'printable';
            }
            if (!isset(
$document[$fieldName]) && isset($documentFieldsAliasesMap[$fieldName]))
            {
                
$fieldName $documentFieldsAliasesMap[$fieldName];
            }

            
$result '';

            if (isset(
$document[$fieldName]))
            {
                
$result $document[$fieldName];
                if (
is_array($result) && strtoupper(substr($fieldName, -strlen('_PRINTABLE'))) == '_PRINTABLE')
                    
$result implode(", "CBPHelper::MakeArrayFlat($result));

                
$property = isset($documentFields[$fieldName]) ? $documentFields[$fieldName] : null;
            }
        }
        elseif (
in_array($objectName, ['Template''Variable''Constant']))
        {
            
$rootActivity $this->GetRootActivity();

            if (
substr($fieldName, -strlen("_printable")) == "_printable")
            {
                
$fieldName substr($fieldName0strlen($fieldName) - strlen("_printable"));
                
$modifiers = array('printable');
            }

            switch (
$objectName)
            {
                case 
'Variable':
                    
$result $rootActivity->GetVariable($fieldName);
                    
$property $rootActivity->getVariableType($fieldName);
                    break;
                case 
'Constant':
                    
$result $rootActivity->GetConstant($fieldName);
                    
$property $rootActivity->GetConstantType($fieldName);
                    break;
                default:
                    
$result $rootActivity->__get($fieldName);
                    
$property $rootActivity->getTemplatePropertyType($fieldName);
            }
        }
        elseif (
$objectName === 'GlobalConst')
        {
            
$result Bizproc\Workflow\Type\GlobalConst::getValue($fieldName);
            
$property Bizproc\Workflow\Type\GlobalConst::getById($fieldName);
        }
        elseif (
$objectName == "Workflow")
        {
            
$result $this->GetWorkflowInstanceId();
            
$property = array('Type' => 'string');
        }
        elseif (
$objectName == "User")
        {
            
$result 0;
            if (isset(
$GLOBALS["USER"]) && is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->isAuthorized())
                
$result "user_".$GLOBALS["USER"]->GetID();
            
$property = array('Type' => 'user');
        }
        elseif (
$objectName == "System")
        {
            global 
$DB;

            
$result null;
            
$property = array('Type' => 'datetime');
            
$systemField strtolower($fieldName);
            if (
$systemField === 'now')
            {
                
$result = new Bizproc\BaseType\Value\DateTime();
                
//$result = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
            
}
            elseif (
$systemField === 'nowlocal')
            {
                
$result = new Bizproc\BaseType\Value\DateTime(time(), CTimeZone::GetOffset());
                
//$result = time();
                //if (CTimeZone::Enabled())
                //    $result += CTimeZone::GetOffset();
                //$result = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $result);
            
}
            elseif (
$systemField == 'date')
            {
                
$result = new Bizproc\BaseType\Value\Date();
                
//$result = date($DB->DateFormatToPHP(CSite::GetDateFormat("SHORT")));
                
$property = array('Type' => 'date');
            }
            if (
$result === null)
            {
                
$return false;
            }
        }
        elseif (
$objectName)
        {
            
$activity $this->workflow->GetActivityByName($objectName);
            if (
$activity)
            {
                
$result $activity->__get($fieldName);
                
//if mapping is set, we can apply modifiers (type converting & formatting like `printable`, `bool` etc.)
                
if (isset($activity->arPropertiesTypes[$fieldName]))
                {
                    
$property $activity->arPropertiesTypes[$fieldName];
                }
            }
            else
                
$return false;
        }
        else
            
$return false;

        if (
$property && $result)
        {
            
$fieldTypeObject $documentService->getFieldTypeObject($this->GetDocumentType(), $property);
            if (
$fieldTypeObject)
            {
                
$fieldTypeObject->setDocumentId($this->GetDocumentId());
                
$result $fieldTypeObject->internalizeValue($objectName$result);
            }
        }

        if (
$return)
            
$result $this->applyPropertyValueModifiers($fieldName$property$result$modifiers);
        return 
$return;
    }