CBPVirtualDocument :: GetDocument: Bitrix method

      
<?php 
//  CBPVirtualDocument :: GetDocument()
//  /dist/bitrix/modules/bizproc/classes/general/virtualdocument.php:1255

    
public function GetDocument($documentId)
    {
        
$documentId intval($documentId);
        if (
$documentId <= 0)
            throw new 
CBPArgumentNullException("documentId");

        
$arResult null;

        
$dbDocumentList CIBlockElement::GetList(
            array(),
            array(
"ID" => $documentId"SHOW_NEW" => "Y")
        );
        if (
$objDocument $dbDocumentList->GetNextElement(falsetrue))
        {
            
$arDocumentFields $objDocument->GetFields();
            
$arDocumentProperties $objDocument->GetProperties();

            foreach (
$arDocumentFields as $fieldKey => $fieldValue)
            {
                if (
substr($fieldKey01) == "~")
                    continue;

                
$arResult[$fieldKey] = $fieldValue;
                if (
in_array($fieldKey, array("MODIFIED_BY""CREATED_BY")))
                {
                    
$arResult[$fieldKey] = "user_".$fieldValue;
                    
$arResult[$fieldKey."_PRINTABLE"] = $arDocumentFields[($fieldKey == "MODIFIED_BY") ? "~USER_NAME" "~CREATED_USER_NAME"];
                }
                elseif (
in_array($fieldKey, array("PREVIEW_TEXT""DETAIL_TEXT")))
                {
                    if (
$arDocumentFields[$fieldKey."_TYPE"] == "html")
                        
$arResult[$fieldKey] = HTMLToTxt($arDocumentFields["~".$fieldKey]);
                }
            }

            foreach (
$arDocumentProperties as $propertyKey => $propertyValue)
            {
                if (
strlen($propertyValue["USER_TYPE"]) > 0)
                {
                    if (
$propertyValue["USER_TYPE"] == "UserID"
                        
|| $propertyValue["USER_TYPE"] == "employee" && (COption::GetOptionString("bizproc""employee_compatible_mode""N") != "Y"))
                    {
                        if (!
is_array($propertyValue["VALUE"]))
                        {
                            
$db CUser::GetByID($propertyValue["VALUE"]);
                            if (
$ar $db->fetch())
                            {
                                
$arResult["PROPERTY_".$propertyKey] = "user_".intval($propertyValue["VALUE"]);
                                
$arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = "(".$ar["LOGIN"].")".((strlen($ar["NAME"]) > || strlen($ar["LAST_NAME"]) > 0) ? " " "").CUser::FormatName(COption::GetOptionString("bizproc""name_template"CSite::GetNameFormat(false), SITE_ID), $arfalsefalse);
                            }
                        }
                        else
                        {
                            for (
$i 0$cnt count($propertyValue["VALUE"]); $i $cnt$i++)
                            {
                                
$db CUser::GetByID($propertyValue["VALUE"][$i]);
                                if (
$ar $db->fetch())
                                {
                                    
$arResult["PROPERTY_".$propertyKey][] = "user_".intval($propertyValue["VALUE"][$i]);
                                    
$arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$propertyValue["VALUE"][$i]] = "(".$ar["LOGIN"].")".((strlen($ar["NAME"]) > || strlen($ar["LAST_NAME"]) > 0) ? " " "").CUser::FormatName(COption::GetOptionString("bizproc""name_template"CSite::GetNameFormat(false), SITE_ID), $arfalsefalse);
                                }
                            }
                        }
                    }
                    else
                    {
                        
$arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
                    }
                }
                elseif (
$propertyValue["PROPERTY_TYPE"] == "L")
                {
                    
$arPropertyValue $propertyValue["VALUE"];
                    
$arPropertyKey $propertyValue["VALUE_XML_ID"];
                    if (!
is_array($arPropertyValue))
                    {
                        
$arPropertyValue = array($arPropertyValue);
                        
$arPropertyKey = array($arPropertyKey);
                    }

                    for (
$i 0$cnt count($arPropertyValue); $i $cnt$i++)
                        
$arResult["PROPERTY_".$propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i];
                }
                elseif (
$propertyValue["PROPERTY_TYPE"] == "F")
                {
                    if (!
is_array($propertyValue["VALUE"]))
                    {
                        if ((
intval($propertyValue["VALUE"]) > 0) && ($ar CFile::GetFileArray($propertyValue["VALUE"])))
                        {
                            
$arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
                            
$arResult["PROPERTY_".$propertyKey."_PRINTABLE"] = $ar["SRC"];
                        }
                    }
                    else
                    {
                        for (
$i 0$cnt count($propertyValue["VALUE"]); $i $cnt$i++)
                        {
                            if ((
intval($propertyValue["VALUE"][$i]) > 0) && ($ar CFile::GetFileArray($propertyValue["VALUE"][$i])))
                            {
                                
$arResult["PROPERTY_".$propertyKey][] = $propertyValue["VALUE"][$i];
                                
$arResult["PROPERTY_".$propertyKey."_PRINTABLE"][$propertyValue["VALUE"][$i]] = $ar["SRC"];
                            }
                        }
                    }
                }
                else
                {
                    
$arResult["PROPERTY_".$propertyKey] = $propertyValue["VALUE"];
                }
            }
        }

        return 
$arResult;
    }