• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/mysql/cml2.php
  • Класс: CIBlockXMLFile
  • Вызов: CIBlockXMLFile::GetList
function GetList($arOrder = array(), $arFilter = array(), $arSelect = array(), $handleAttributes = false)
{
	global $DB;

	static $arFields = array(
		"ID" => "ID",
		"ATTRIBUTES" => "ATTRIBUTES",
		"LEFT_MARGIN" => "LEFT_MARGIN",
		"RIGHT_MARGIN" => "RIGHT_MARGIN",
		"NAME" => "NAME",
		"VALUE" => "VALUE",
	);
	foreach($arSelect as $i => $field)
	{
		if (!isset($arFields[$field]))
		{
			unset($arSelect[$i]);
		}
	}
	if (empty($arSelect))
	{
		$arSelect[] = "*";
	}

	$arSQLWhere = array();
	foreach($arFilter as $field => $value)
	{
		if($field == "ID" && is_array($value) && !empty($value))
		{
			MainTypeCollection::normalizeArrayValuesByInt($value, false);
			if (!empty($value))
			{
				$arSQLWhere[$field] = $field . " in (" . implode(",", $value) . ")";
			}
		}
		elseif($field == "ID" || $field == "LEFT_MARGIN")
			$arSQLWhere[$field] = $field." = ".(int)$value;
		elseif($field == "PARENT_ID" || $field == "PARENT_ID+0")
			$arSQLWhere[$field] = $field." = ".(int)$value;
		elseif($field == ">ID")
			$arSQLWhere[$field] = "ID > ".(int)$value;
		elseif($field == ">ForSQL($value)."'";
	}
	if($this->_sessid)
		$arSQLWhere[] = "SESS_ID = '".$DB->ForSQL($this->_sessid)."'";

	foreach($arOrder as $field => $by)
	{
		if(!isset($arFields[$field]))
		{
			unset($arSelect[$field]);
		}
		else
		{
			$arOrder[$field] = $field . " " . ($by == "desc" ? "desc" : "asc");
		}
	}

	$strSql = "
		select
			".implode(", ", $arSelect)."
		from
			".$this->_table_name."
		".(count($arSQLWhere)? "where (".implode(") and (", $arSQLWhere).")": "")."
		".(count($arOrder)? "order by  ".implode(", ", $arOrder): "")."
	";

	if ($handleAttributes)
	{
		$result = new CCMLResult($DB->Query($strSql));
	}
	else
	{
		$result = $DB->Query($strSql);
	}
	return $result;
}