• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/comp_findtools.php
  • Класс: CIBlockFindTools
  • Вызов: CIBlockFindTools::checkSection
static function checkSection($iblock_id, &$arVariables)
{
	global $DB;

	$sectionPath = explode("/", $arVariables["SECTION_CODE_PATH"]);

	// B24 fix
	if (count($sectionPath) > 61)
		return false;

	$strFrom = "";
	$joinField = "";
	$strWhere = "";
	$strRoot = "";
	foreach (array_reverse($sectionPath) as $i => $SECTION_CODE)
	{
		if ($i == 0)
		{
			$strFrom .= "
				b_iblock_section BS
			";
			$joinField .= "BS.IBLOCK_SECTION_ID";
			$strWhere .= "
				AND BS.CODE = '".$DB->ForSql($SECTION_CODE)."'
			";
			$strRoot = "AND BS.IBLOCK_SECTION_ID IS NULL";
		}
		else
		{
			$strFrom .= "
				INNER JOIN b_iblock_section BS".$i." ON BS".$i.".ID = ".$joinField."
			";
			$joinField = "BS".$i.".IBLOCK_SECTION_ID";
			$strWhere .= "
				AND BS".$i.".CODE = '".$DB->ForSql($SECTION_CODE)."'
			";
			$strRoot = "AND BS".$i.".IBLOCK_SECTION_ID IS NULL";
		}
	}

	$strSql = "
		select BS.ID
		from ".$strFrom."
		WHERE BS.IBLOCK_ID = ".$iblock_id."
		".$strWhere."
		".$strRoot."
	";
	$rs = $DB->Query($strSql);
	if ($ar = $rs->Fetch())
	{
		$arVariables["SECTION_ID"] = $ar["ID"];
		$arVariables["SECTION_CODE"] = $sectionPath[count($sectionPath)-1];
		return true;
	}
	else
	{
		return false;
	}
}