- Модуль: forum
- Путь к файлу: ~/bitrix/modules/forum/classes/mysql/filter_dictionary.php
- Класс: CFilterDictionary
- Вызов: CFilterDictionary::GetList
static function GetList($arOrder = array("ID"=>"ASC"), $arFilter = array(), $bCount = false)
{
global $DB;
$arSqlSearch = array();
$strSqlSearch = "";
$arSqlOrder = array();
$strSqlOrder = "";
$arFilter = (is_array($arFilter) ? $arFilter : array());
foreach ($arFilter as $key => $val)
{
$key_res = CFilterDictionary::GetFilterOperation($key);
$key = mb_strtoupper($key_res["FIELD"]);
$strNegative = $key_res["NEGATIVE"];
$strOperation = $key_res["OPERATION"];
switch ($key)
{
case "TYPE":
case "TITLE":
if ($val == '')
$arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FD.".$key." IS NULL OR LENGTH(FD.".$key.")<=0)";
else
$arSqlSearch[] = ($strNegative=="Y"?" FD.".$key." IS NULL OR NOT ":"")."(FD.".$key." ".$strOperation." '".$DB->ForSql($val)."' )";
break;
case "ID":
if ($strOperation!="IN")
{
if (intval($val)<=0)
$arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FD.ID IS NULL OR FD.ID<=0)";
else
$arSqlSearch[] = ($strNegative=="Y"?" FD.ID IS NULL OR NOT ":"")."(FD.ID ".$strOperation." ".intval($val)." )";
}
else
{
if (!is_array($val))
$val = explode(',', $val);
$val_int=array();
foreach($val as $v)
$val_int[] = intval($v);
$val = implode(', ', $val_int);
$arSqlSearch[] = ($strNegative=="Y"?" NOT ":"")."(FD.ID IN (".$DB->ForSql($val).") )";
}
break;
}
}
if (!empty($arSqlSearch))
$strSqlSearch = "WHERE (".implode(") AND (", $arSqlSearch).")";
foreach ($arOrder as $by => $order)
{
$by = mb_strtoupper($by);
$order = mb_strtoupper($order);
if ($order!="ASC") $order = "DESC";
if ($by == "ID") $arSqlOrder[] = " FD.ID ".$order." ";
elseif ($by == "TITLE") $arSqlOrder[] = " FD.TITLE ".$order." ";
else
{
$arSqlOrder[] = " FD.ID ".$order." ";
$by = "ID";
}
}
DelDuplicateSort($arSqlOrder);
if (!empty($arSqlOrder))
$strSqlOrder = " ORDER BY ".implode(", ", $arSqlOrder);
if ($bCount)
{
$strSql = "SELECT COUNT(FD.ID) as CNT FROM b_forum_dictionary FD ".$strSqlSearch;
$db_res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
$iCnt = 0;
if ($ar_res = $db_res->Fetch())
$iCnt = intval($ar_res["CNT"]);
return $iCnt;
}
$strSql = "SELECT FD.ID, FD.TITLE, FD.TYPE FROM b_forum_dictionary FD ".$strSqlSearch.$strSqlOrder;
$db_res = $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
return $db_res;
}