Beispiel #1
0
 function GetListEx($arOrder = array(), $arFilter = array())
 {
     global $DB;
     $arSqlSearch = array();
     $arOrder = is_array($arOrder) ? $arOrder : array();
     $arFilter = is_array($arFilter) ? $arFilter : array();
     foreach ($arFilter as $key => $val) {
         $key_res = CVote::GetFilterOperation($key);
         $key = strtoupper($key_res["FIELD"]);
         $strNegative = $key_res["NEGATIVE"];
         $strOperation = $key_res["OPERATION"];
         switch ($key) {
             case "CHANNEL_ID":
             case "COUNTER":
             case "ID":
                 $str = ($strNegative == "Y" ? "NOT" : "") . "(V." . $key . " IS NULL OR V." . $key . "<=0)";
                 if (!empty($val)) {
                     $str = ($strNegative == "Y" ? " V." . $key . " IS NULL OR NOT " : "") . "(V." . $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 " : "") . "(V." . $key . " IN (" . implode(",", $val) . "))";
                         }
                     }
                 }
                 $arSqlSearch[] = $str;
                 break;
             case "ACTIVE":
                 if (empty($val)) {
                     $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(V." . $key . " IS NULL OR LENGTH(V." . $key . ")<=0)";
                 } else {
                     $arSqlSearch[] = ($strNegative == "Y" ? " V." . $key . " IS NULL OR NOT " : "") . "(V." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "' )";
                 }
                 break;
             case "DATE_START":
             case "DATE_END":
                 if (empty($val)) {
                     $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(V." . $key . " IS NULL OR LENGTH(V." . $key . ")<=0)";
                 } else {
                     $arSqlSearch[] = ($strNegative == "Y" ? " V." . $key . " IS NULL OR NOT " : "") . "(V." . $key . " " . $strOperation . " " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . " )";
                 }
                 break;
         }
     }
     $strSqlSearch = !empty($arSqlSearch) ? " AND (" . implode(") AND (", $arSqlSearch) . ") " : "";
     $arSqlOrder = array();
     foreach ($arOrder as $by => $order) {
         $by = strtoupper($by);
         $by = in_array($by, array("ID", "TITLE", "DATE_START", "DATE_END", "COUNTER", "ACTIVE", "C_SORT", "CHANNEL_ID")) ? $by : "ID";
         $arSqlOrder[] = "V." . $by . " " . (strtoupper($order) == "ASC" ? "ASC" : "DESC");
     }
     DelDuplicateSort($arSqlOrder);
     $strSqlOrder = !empty($arSqlOrder) ? "ORDER BY " . implode(",", $arSqlOrder) : "";
     $strSql = "\n\t\t\tSELECT V.*,\n\t\t\t\tC.TITLE as CHANNEL_TITLE,\n\t\t\t\tC.SYMBOLIC_NAME as CHANNEL_SYMBOLIC_NAME,\n\t\t\t\tC.C_SORT as CHANNEL_C_SORT,\n\t\t\t\tC.FIRST_SITE_ID as CHANNEL_FIRST_SITE_ID,\n\t\t\t\tC.ACTIVE as CHANNEL_ACTIVE,\n\t\t\t\tC.HIDDEN as CHANNEL_HIDDEN,\n\t\t\t\tC.TITLE as CHANNEL_TITLE,\n\t\t\t\tC.VOTE_SINGLE as CHANNEL_VOTE_SINGLE,\n\t\t\t\tC.USE_CAPTCHA as CHANNEL_USE_CAPTCHA,\n\t\t\t\t" . $DB->DateToCharFunction("V.TIMESTAMP_X") . " TIMESTAMP_X,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_START") . " DATE_START,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_END") . " DATE_END,\n\t\t\t\tCASE WHEN (C.ACTIVE = 'Y' AND V.ACTIVE = 'Y' AND V.DATE_START <= NOW() AND NOW() <= V.DATE_END)\n\t\t\t\t\tTHEN IF (C.VOTE_SINGLE != 'Y', 'green', 'yellow')\n\t\t\t\t\tELSE 'red'\n\t\t\t\tEND AS LAMP\n\t\t\tFROM b_vote V\n\t\t\tINNER JOIN b_vote_channel C ON (V.CHANNEL_ID = C.ID)\n\t\t\tWHERE 1=1 " . $strSqlSearch . " " . $strSqlOrder;
     return new _CVoteDBResult($DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__));
 }