static function GetList($arOrder = false, $arFilter = false, $arSelect = false, $bGroup = false)
{
$DB = CDatabase::GetModuleConnection('search');
static $arDefSelect = array(
"ID",
"TIMESTAMP_X",
"SITE_ID",
"RESULT_COUNT",
"PAGES",
"PHRASE",
"TAGS",
"URL_TO",
"URL_TO_404",
"URL_TO_SITE_ID",
"STAT_SESS_ID",
);
if (!is_array($arSelect))
$arSelect = array();
if (count($arSelect) < 1)
$arSelect = $arDefSelect;
if (!is_array($arOrder))
$arOrder = array();
if (count($arOrder) < 1)
$arOrder = array(
"ID" => "DESC",
);
$arQueryOrder = array();
foreach ($arOrder as $strColumn => $strDirection)
{
$strColumn = mb_strtoupper($strColumn);
$strDirection = mb_strtoupper($strDirection) == "ASC"? "ASC": "DESC";
if (in_array($strColumn, $arDefSelect))
{
$arSelect[] = $strColumn;
if ($strColumn == "TIMESTAMP_X")
$arQueryOrder[$strColumn] = "TMP_TS ".$strDirection;
else
$arQueryOrder[$strColumn] = $strColumn." ".$strDirection;
}
elseif ($strColumn == "COUNT" && $bGroup)
{
$arSelect[] = $strColumn;
$arQueryOrder[$strColumn] = $strColumn." ".$strDirection;
}
}
$arQueryGroup = array();
$arQuerySelect = array();
foreach ($arSelect as $strColumn)
{
$strColumn = mb_strtoupper($strColumn);
if (in_array($strColumn, $arDefSelect))
{
if ($strColumn == "TIMESTAMP_X")
{
$arQuerySelect["TMP_TS"] = "sph.".$strColumn." TMP_TS";
$arQuerySelect[$strColumn] = $DB->DateToCharFunction("sph.".$strColumn, "FULL")." ".$strColumn;
}
else
{
$arQuerySelect[$strColumn] = "sph.".$strColumn;
}
if ($bGroup)
$arQueryGroup[$strColumn] = "sph.".$strColumn;
}
elseif ($strColumn == "COUNT" && $bGroup)
{
$arQuerySelect[$strColumn] = "count(*) ".$strColumn;
}
}
$obQueryWhere = new CSQLWhere;
$obQueryWhere->SetFields(array(
"ID" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.ID",
"FIELD_TYPE" => "int", //int, double, file, enum, int, string, date, datetime
"JOIN" => false,
),
"PHRASE" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.PHRASE",
"FIELD_TYPE" => "string",
"JOIN" => false,
),
"TAGS" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.TAGS",
"FIELD_TYPE" => "string",
"JOIN" => false,
),
"TIMESTAMP_X" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.TIMESTAMP_X",
"FIELD_TYPE" => "datetime",
"JOIN" => false,
),
"SITE_ID" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.SITE_ID",
"FIELD_TYPE" => "string",
"JOIN" => false,
),
"URL_TO" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.URL_TO",
"FIELD_TYPE" => "string",
"JOIN" => false,
),
"URL_TO_404" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.URL_TO_404",
"FIELD_TYPE" => "string",
"JOIN" => false,
),
"STAT_SESS_ID" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.STAT_SESS_ID",
"FIELD_TYPE" => "int",
"JOIN" => false,
),
"RESULT_COUNT" => array(
"TABLE_ALIAS" => "sph",
"FIELD_NAME" => "sph.RESULT_COUNT",
"FIELD_TYPE" => "int",
"JOIN" => false,
),
));
if (count($arQuerySelect) < 1)
$arQuerySelect = array("ID" => "sph.ID");
$strSql = "
SELECT
".implode(", ", $arQuerySelect)."
FROM
b_search_phrase sph
";
if (!is_array($arFilter))
$arFilter = array();
if ($strQueryWhere = $obQueryWhere->GetQuery($arFilter))
{
$strSql .= "
WHERE
".$strQueryWhere."
";
}
if ($bGroup && count($arQueryGroup) > 0)
{
$strSql .= "
GROUP BY
".implode(", ", $arQueryGroup)."
";
}
if (count($arQueryOrder) > 0)
{
$strSql .= "
ORDER BY
".implode(", ", $arQueryOrder)."
";
}
return $DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
}