- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockresult.php
- Класс: CIBlockResult
- Вызов: CIBlockResult::Fetch
function Fetch()
{
/** @global CDatabase $DB */
global $DB;
$res = parent::Fetch();
if(!isset($this) || !is_object($this))
return $res;
if($res)
{
$arUpdate = array();
if(!empty($this->arIBlockLongProps) && is_array($this->arIBlockLongProps))
{
foreach($res as $k=>$v)
{
if(preg_match("#^ALIAS_(\d+)_(.*)$#", $k, $match))
{
$res[$this->arIBlockLongProps[$match[1]].$match[2]] = $v;
unset($res[$k]);
}
}
}
if(
isset($res["IBLOCK_ID"])
&& $res["IBLOCK_ID"] != $this->_LAST_IBLOCK_ID
&& defined("BX_COMP_MANAGED_CACHE")
)
{
CIBlock::registerWithTagCache($res["IBLOCK_ID"]);
$this->_LAST_IBLOCK_ID = $res["IBLOCK_ID"];
}
if(isset($res["ID"]) && $res["ID"] != "" && !empty($this->arIBlockMultProps) && is_array($this->arIBlockMultProps))
{
foreach($this->arIBlockMultProps as $field_name => $db_prop)
{
if(array_key_exists($field_name, $res))
{
if(is_object($res[$field_name]))
$res[$field_name]=$res[$field_name]->load();
if(preg_match("/(_VALUE)$/", $field_name))
{
$descr_name = preg_replace("/(_VALUE)$/", "_DESCRIPTION", $field_name);
$value_id_name = preg_replace("/(_VALUE)$/", "_PROPERTY_VALUE_ID", $field_name);;
}
else
{
$descr_name = preg_replace("/^(PROPERTY_)/", "DESCRIPTION_", $field_name);
$value_id_name = preg_replace("/^(PROPERTY_)/", "PROPERTY_VALUE_ID_", $field_name);
}
$update = false;
if ($res[$field_name] == '')
{
$update = true;
}
else
{
$tmp = unserialize($res[$field_name], ['allowed_classes' => false]);
if (!isset($tmp['ID']))
$update = true;
}
if ($update)
{
$strSql = "
SELECT ID, VALUE, DESCRIPTION
FROM b_iblock_element_prop_m".$db_prop["IBLOCK_ID"]."
WHERE
IBLOCK_ELEMENT_ID = ".intval($res["ID"])."
AND IBLOCK_PROPERTY_ID = ".intval($db_prop["ORIG_ID"])."
ORDER BY ID
";
$rs = $DB->Query($strSql);
$res[$field_name] = array();
$res[$descr_name] = array();
$res[$value_id_name] = array();
while($ar=$rs->Fetch())
{
$res[$field_name][]=$ar["VALUE"];
$res[$descr_name][]=$ar["DESCRIPTION"];
$res[$value_id_name][] = $ar['ID'];
}
$arUpdate["b_iblock_element_prop_s".$db_prop["IBLOCK_ID"]]["PROPERTY_".$db_prop["ORIG_ID"]] = serialize(array("VALUE"=>$res[$field_name],"DESCRIPTION"=>$res[$descr_name],"ID"=>$res[$value_id_name]));
}
else
{
$res[$field_name] = $tmp["VALUE"];
$res[$descr_name] = $tmp["DESCRIPTION"];
$res[$value_id_name] = $tmp["ID"];
}
if(is_array($res[$field_name]) && $db_prop["PROPERTY_TYPE"]=="L")
{
$arTemp = array();
foreach($res[$field_name] as $key=>$val)
{
$arEnum = CIBlockPropertyEnum::GetByID($val);
if($arEnum!==false)
$arTemp[$val] = $arEnum["VALUE"];
}
$res[$field_name] = $arTemp;
}
}
}
if (!empty($arUpdate))
{
$pool = BitrixMainApplication::getInstance()->getConnectionPool();
$pool->useMasterOnly(true);
foreach ($arUpdate as $strTable => $arFields)
{
$strUpdate = $DB->PrepareUpdate($strTable, $arFields);
if ($strUpdate != "")
{
$strSql = "UPDATE ".$strTable." SET ".$strUpdate." WHERE IBLOCK_ELEMENT_ID = ".intval($res["ID"]);
$DB->QueryBind($strSql, $arFields);
}
}
$pool->useMasterOnly(false);
unset($pool);
}
}
if(!empty($this->arIBlockConvProps) && is_array($this->arIBlockConvProps))
{
foreach($this->arIBlockConvProps as $strFieldName=>$arCallback)
{
if(is_array($res[$strFieldName]))
{
foreach($res[$strFieldName] as $key=>$value)
{
$arValue = call_user_func_array(
$arCallback['ConvertFromDB'],
[
$arCallback['PROPERTY'],
[
'VALUE' => $value,
'DESCRIPTION' => '',
]
]
);
$res[$strFieldName][$key] = $arValue['VALUE'] ?? null;
}
}
else
{
$arValue = call_user_func_array(
$arCallback['ConvertFromDB'],
[
$arCallback['PROPERTY'],
[
'VALUE' => $res[$strFieldName],
'DESCRIPTION' => '',
]
]
);
$res[$strFieldName] = $arValue['VALUE'] ?? null;
}
}
}
if(!empty($this->arIBlockNumProps) && is_array($this->arIBlockNumProps))
{
foreach($this->arIBlockNumProps as $field_name => $db_prop)
{
if($res[$field_name] <> '')
$res[$field_name] = htmlspecialcharsex(CIBlock::NumberFormat($res[$field_name]));
}
}
if (isset($res["UC_ID"]))
{
$res["CREATED_BY_FORMATTED"] = CUser::FormatName($this->nameTemplate, array(
"NAME" => $res["UC_NAME"],
"LAST_NAME" => $res["UC_LAST_NAME"],
"SECOND_NAME" => $res["UC_SECOND_NAME"],
"EMAIL" => $res["UC_EMAIL"],
"ID" => $res["UC_ID"],
"LOGIN" => $res["UC_LOGIN"],
), true, false);
unset($res["UC_NAME"]);
unset($res["UC_LAST_NAME"]);
unset($res["UC_SECOND_NAME"]);
unset($res["UC_EMAIL"]);
unset($res["UC_ID"]);
unset($res["UC_LOGIN"]);
}
unset($arUpdate);
}
elseif(
defined("BX_COMP_MANAGED_CACHE")
&& $this->_LAST_IBLOCK_ID == ""
&& count($this->_FILTER_IBLOCK_ID)
)
{
foreach($this->_FILTER_IBLOCK_ID as $iblock_id => $t)
CIBlock::registerWithTagCache($iblock_id);
}
return $res;
}