• Модуль: vote
  • Путь к файлу: ~/bitrix/modules/vote/classes/general/question.php
  • Класс: CAllVoteQuestion
  • Вызов: CAllVoteQuestion::GetListEx
static function GetListEx($arOrder = array("ID" => "ASC"), $arFilter=array())
{
	global $DB;

	$arSqlSearch = array();
	$strSqlSearch = "";
	$arSqlOrder = array();
	$strSqlOrder = "";

	$arFilter = (is_array($arFilter) ? $arFilter : array());
	foreach ($arFilter as $key => $val)
	{
		if($val === "NOT_REF")
			continue;
		$key_res = VoteGetFilterOperation($key);
		$strNegative = $key_res["NEGATIVE"];
		$strOperation = $key_res["OPERATION"];
		$key = mb_strtoupper($key_res["FIELD"]);

		switch($key)
		{
			case "ID":
			case "VOTE_ID":
				$str = ($strNegative=="Y"?"NOT":"")."(VQ.".$key." IS NULL OR VQ.".$key."<=0)";
				if (!empty($val))
				{
					$str = ($strNegative=="Y"?" VQ.".$key." IS NULL OR NOT ":"")."(VQ.".$key." ".$strOperation." ".intval($val).")";
					if ($strOperation == "IN")
					{
						$val = array_unique(array_map("intval", (is_array($val) ? $val : explode(",", $val))), SORT_NUMERIC);
						if (!empty($val))
						{
							$str = ($strNegative=="Y"?" NOT ":"")."(VQ.".$key." IN (".implode(",", $val)."))";
						}
					}
				}
				$arSqlSearch[] = $str;
				break;
			case "CHANNEL_ID":
				if ($val == '')
					$arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(V.".$key." IS NULL OR V.".$key."<=0)";
				else
					$arSqlSearch[] = ($strNegative=="Y"?" V.".$key." IS NULL OR NOT ":"")."(V.".$key." ".$strOperation." ".intval($val).")";
				break;
			case "ACTIVE":
				if (empty($val))
					$arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(VQ.".$key." IS NULL OR ".($DB->type == "MSSQL" ? "LEN" : "LENGTH")."(VQ.".$key.")<=0)";
				else
					$arSqlSearch[] = ($strNegative=="Y"?" VQ.".$key." IS NULL OR NOT ":"")."(VQ.".$key." ".$strOperation." '".$DB->ForSql($val)."')";
				break;
		}
	}
	if (count($arSqlSearch) > 0)
		$strSqlSearch = " AND (".implode(") AND (", $arSqlSearch).") ";

	foreach ($arOrder as $by => $order)
	{
		$by = mb_strtoupper($by);
		$order = mb_strtoupper($order);
		$by = ($by == "ACTIVE" ? $by : "ID");
		if ($order!="ASC") $order = "DESC";
		if ($by == "ACTIVE") $arSqlOrder[] = " VQ.ACTIVE ".$order." ";
		else $arSqlOrder[] = " VQ.ID ".$order." ";
	}
	DelDuplicateSort($arSqlOrder);
	if (count($arSqlOrder) > 0)
		$strSqlOrder = " ORDER BY ".implode(", ", $arSqlOrder);

	$strSql = "
		SELECT VQ.*
		FROM
			b_vote_question VQ, b_vote V
		WHERE VQ.VOTE_ID = V.ID ".
		$strSqlSearch."
		".$strSqlOrder;
	return $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__); }