• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/mysql/cml2.php
  • Класс: is
  • Вызов: is::GetAllChildrenArray
function GetAllChildrenArray($arParent, $handleAttributes = false)
{
	//We will return
	$arResult = array();

	//So we get not parent itself but xml_id
	if(!is_array($arParent))
	{
		$rs = $this->GetList(
			array(),
			array("ID" => $arParent),
			array("ID", "LEFT_MARGIN", "RIGHT_MARGIN"),
			$handleAttributes
		);
		$arParent = $rs->Fetch();
		if(!$arParent)
			return $arResult;
	}

	//Array of the references to the arResult array members with xml_id as index.
	$arSalt = array();
	$arIndex = array();
	$rs = $this->GetList(
		array("ID" => "asc"),
		array("> array($arParent["LEFT_MARGIN"]+1, $arParent["RIGHT_MARGIN"]-1)),
		array(),
		$handleAttributes
	);
	while($ar = $rs->Fetch())
	{
		if (
			(int)$ar['PARENT_ID'] === 0
			&& (int)$ar['RIGHT_MARGIN'] === 0
			&& (int)$ar['DEPTH_LEVEL'] === 0
			&& $ar['NAME'] === ''
		)
		{
			continue;
		}
		if(isset($ar["VALUE_CLOB"]))
			$ar["VALUE"] = $ar["VALUE_CLOB"];

		if(isset($arSalt[$ar["PARENT_ID"]][$ar["NAME"]]))
		{
			$salt = ++$arSalt[$ar["PARENT_ID"]][$ar["NAME"]];
			$ar["NAME"] .= $salt;
		}
		else
		{
			$arSalt[$ar["PARENT_ID"]][$ar["NAME"]] = 0;
		}

		if($ar["PARENT_ID"] == $arParent["ID"])
		{
			$arResult[$ar["NAME"]] = $ar["VALUE"];
			$arIndex[$ar["ID"]] = &$arResult[$ar["NAME"]];
		}
		else
		{
			$parent_id = $ar["PARENT_ID"];
			if (!is_array($arIndex[$parent_id]))
			{
				$arIndex[$parent_id] = [];
			}
			$arIndex[$parent_id][$ar["NAME"]] = $ar["VALUE"];
			$arIndex[$ar["ID"]] = &$arIndex[$parent_id][$ar["NAME"]];
		}
	}
	unset($ar);
	unset($rs);
	unset($arIndex);
	unset($arSalt);

	return $arResult;
}