Ejemplo n.º 1
0
 function GetList(&$arSort, $arFilter = array(), &$isFiltered)
 {
     $err_mess = CTicketSLA::err_mess() . "<br>Function: GetList<br>Line: ";
     global $DB, $USER, $APPLICATION;
     $isFiltered = false;
     // filter params correct
     if (CTicket::CheckFilter($arFilter)) {
         $arSqlSearch = array();
         if (is_array($arFilter) && count($arFilter) > 0) {
             $filterKeys = array_keys($arFilter);
             $filterKeysCount = count($filterKeys);
             for ($i = 0; $i < $filterKeysCount; $i++) {
                 $key = $filterKeys[$i];
                 $val = $arFilter[$filterKeys[$i]];
                 if (is_array($val) && count($val) <= 0 || !is_array($val) && (strlen($val) <= 0 || $val === 'NOT_REF')) {
                     continue;
                 }
                 $matchValueSet = in_array($key . "_EXACT_MATCH", $filterKeys) ? true : false;
                 $key = strtoupper($key);
                 if (is_array($val)) {
                     $val = implode(" | ", $val);
                 }
                 switch ($key) {
                     case "ID":
                     case "SLA_ID":
                         $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $matchValueSet ? "Y" : "N";
                         $arSqlSearch[] = GetFilterQuery("S." . $key, $val, $match);
                         break;
                     case "NAME":
                     case "DESCRIPTION":
                     case "DEADLINE_SOURCE":
                         $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $matchValueSet ? "N" : "Y";
                         $arSqlSearch[] = GetFilterQuery("S." . $key, $val, $match);
                         break;
                     case "SITE":
                         $val .= " | ALL";
                         $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $matchValueSet ? "Y" : "N";
                         $arSqlSearch[] = GetFilterQuery("SS.SITE_ID", $val, $match);
                         $left_join_site = "LEFT JOIN b_ticket_sla_2_site SS ON (S.ID = SS.SLA_ID)";
                         break;
                 }
             }
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $arSort = is_array($arSort) ? $arSort : array();
     if (count($arSort) > 0) {
         $ar1 = array_merge($DB->GetTableFieldsList("b_ticket_sla"), array());
         $ar2 = array_keys($arSort);
         $arDiff = array_diff($ar2, $ar1);
         if (is_array($arDiff) && count($arDiff) > 0) {
             foreach ($arDiff as $value) {
                 unset($arSort[$value]);
             }
         }
     }
     if (count($arSort) <= 0) {
         $arSort = array("PRIORITY" => "DESC");
     }
     while (list($by, $order) = each($arSort)) {
         if (strtoupper($order) != "DESC") {
             $order = "ASC";
         }
         if ($by == "RESPONSE_TIME") {
             $arSqlOrder[] = "case RESPONSE_TIME_UNIT when 'day' then 3 when 'hour' then 2 when 'minute' then 1 end {$order}";
             $arSqlOrder[] = $by . " " . $order;
         } else {
             $arSqlOrder[] = $by . " " . $order;
         }
     }
     if (is_array($arSqlOrder) && count($arSqlOrder) > 0) {
         $strSqlOrder = " ORDER BY " . implode(",", $arSqlOrder);
     }
     $strSql = "\n\t\t\tSELECT DISTINCT\n\t\t\t\tS.*,\n\t\t\t\tcase S.RESPONSE_TIME_UNIT\n\t\t\t\t\twhen 'day' then S.RESPONSE_TIME*1440\n\t\t\t\t\twhen 'hour' then S.RESPONSE_TIME*60\n\t\t\t\t\twhen 'minute' then S.RESPONSE_TIME\n\t\t\t\t\tend\t\t\t\t\t\t\t\t\t\t\tM_RESPONSE_TIME,\n\t\t\t\tcase S.NOTICE_TIME_UNIT\n\t\t\t\t\twhen 'day' then S.NOTICE_TIME*1440\n\t\t\t\t\twhen 'hour' then S.NOTICE_TIME*60\n\t\t\t\t\twhen 'minute' then S.NOTICE_TIME\n\t\t\t\t\tend\t\t\t\t\t\t\t\t\t\t\tM_NOTICE_TIME,\n\t\t\t\tS.ID\t\t\t\t\t\t\t\t\t\t\tREFERENCE_ID,\n\t\t\t\tS.NAME\t\t\t\t\t\t\t\t\t\t\tREFERENCE,\n\t\t\t\t" . $DB->DateToCharFunction("S.DATE_MODIFY") . "\tDATE_MODIFY_F,\n\t\t\t\t" . $DB->DateToCharFunction("S.DATE_CREATE") . "\tDATE_CREATE_F\n\t\t\tFROM\n\t\t\t\tb_ticket_sla S\n\t\t\t{$left_join_site}\n\t\t\tWHERE\n\t\t\t{$strSqlSearch}\n\t\t\t{$strSqlOrder}\n\t\t\t";
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     $isFiltered = IsFiltered($strSqlSearch);
     return $rs;
 }