Ejemplo n.º 1
0
 function GetSheduleByID($id, $needObj = false)
 {
     global $DB;
     $err_mess = self::err_mess() . "<br>Function: Set<br>Line: ";
     $tableShedule = self::TABLE_SHEDULE;
     $id = intval($id);
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tT.*\n\t\t\tFROM\n\t\t\t\t{$tableShedule} T\n\t\t\tWHERE\n\t\t\t\tT.TIMETABLE_ID = {$id}\n\t\t\t";
     $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     if (!$needObj) {
         return $res;
     }
     $f_s = new CSupportTableFields(self::$fieldsTypesShedule, CSupportTableFields::C_Table);
     $f_s->RemoveExistingRows();
     while ($resR = $res->Fetch()) {
         $f_s->AddRow();
         $f_s->FromArray($resR);
     }
     return $f_s;
 }
Ejemplo n.º 2
0
 function GetSLAByID($id, $needObj = false)
 {
     $err_mess = self::err_mess() . "<br>Function: GetList<br>Line: ";
     global $DB, $USER, $APPLICATION;
     $table_s2h = self::table_s2h;
     $table_sla = self::table_sla;
     $id = intval($id);
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tS2H.HOLIDAYS_ID,\n\t\t\t\tS2H.SLA_ID,\n\t\t\t\tSLA.NAME\n\t\t\tFROM\n\t\t\t\t{$table_s2h} S2H\n\t\t\t\tINNER JOIN {$table_sla} SLA\n\t\t\t\t\tON S2H.SLA_ID = SLA.ID\n\t\t\t\t\t\tAND S2H.HOLIDAYS_ID = {$id}\n\t\t\tORDER BY\n\t\t\t\tSLA.NAME\n\t\t\t";
     $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     if (!$needObj) {
         return $res;
     }
     $f_s = new CSupportTableFields(self::$sla2holidays, CSupportTableFields::C_Table);
     $f_s->RemoveExistingRows();
     while ($resR = $res->Fetch()) {
         $f_s->AddRow();
         $f_s->FromArray($resR);
     }
     return $f_s;
 }
Ejemplo n.º 3
0
 public static function ToCache($arFilter = array(), $RSD = true, $arFromGetEndDate = null)
 {
     /*
     $arFilter(
     	SLA => array()
     )
     */
     global $DB;
     $currD = time();
     $uniq = "";
     $dbType = strtolower($DB->type);
     if ($dbType === "mysql") {
         $DB->StartUsingMasterOnly();
         $uniq = COption::GetOptionString("main", "server_uniq_id", "");
         if (strlen($uniq) <= 0) {
             $uniq = md5(uniqid(rand(), true));
             COption::SetOptionString("main", "server_uniq_id", $uniq);
         }
         $db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_supportToCache', 0) as L");
         $ar_lock = $db_lock->Fetch();
         if ($ar_lock["L"] !== "1") {
             return;
         }
         //Перед пересчетом проверить в центральной базе что данных действительно нет, на случй здержки передачм данных в дочернюю базу(только для MYSQL)
         if (is_array($arFromGetEndDate)) {
             $res = self::getEndDate($arFromGetEndDate["SLA"], $arFromGetEndDate["PERIOD_MIN"], $arFromGetEndDate["DATE_FROM"], true);
             if ($res !== null) {
                 return $res;
             }
         }
     }
     $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: ";
     $timetable_cache = self::TIMETABLE_CACHE;
     $ndF = self::GetNumberOfDaysForward();
     $ndB = self::GetNumberOfDaysBackward();
     $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60);
     $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60);
     self::$arrS = self::GetShedule($arFilter);
     if (count(self::$arrS) <= 0) {
         return null;
     }
     self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter);
     $arrSLA = array_keys(self::$arrS);
     $arSqlSearch = array();
     foreach ($arFilter as $key => $val) {
         if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) {
             continue;
         }
         $key = strtoupper($key);
         if (is_array($val)) {
             $val = implode(" | ", $val);
         }
         switch ($key) {
             case "SLA_ID":
                 $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N");
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__);
     $f = new CSupportTableFields(self::$cache);
     $colNames = null;
     $strList = "";
     $coma = "";
     foreach ($arrSLA as $k => $sla) {
         $dateC = $dateF;
         $sum = 0;
         while ($dateC <= $dateT) {
             if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) {
                 $a = self::$arrH[$sla][$dateC];
             } else {
                 $a = self::$arrS[$sla][self::GetDayNom($dateC)];
             }
             foreach ($a as $k2 => $v2) {
                 $sum = $sum + $v2["T"] - $v2["F"];
                 $f->SLA_ID = $sla;
                 $f->DATE_FROM = $dateC + $v2["F"];
                 $f->DATE_TILL = $dateC + $v2["T"];
                 $f->W_TIME = $v2["T"] - $v2["F"];
                 $f->W_TIME_INC = $sum;
                 CTimeZone::Disable();
                 if ($dbType === "mysql") {
                     $arCurrTicketFields = $f->ToArray(CSupportTableFields::ALL, array(), true);
                     if ($colNames === null) {
                         $colNames = implode(", ", array_keys($arCurrTicketFields));
                     }
                     $strCurrTicketFields = "(" . implode(",", $arCurrTicketFields) . ")";
                     if (strlen($strList . ", " . $strCurrTicketFields) > 2000) {
                         $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList;
                         $strList = $strCurrTicketFields;
                     } else {
                         $strList .= $coma . $strCurrTicketFields;
                         $coma = ", ";
                         continue;
                     }
                     $DB->Query($strSql, false, $err_mess . __LINE__);
                 } else {
                     $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__);
                 }
                 CTimeZone::Enable();
             }
             $dateC = self::GetDayBegin($dateC + 25 * 60 * 60);
         }
     }
     if ($dbType === "mysql") {
         if (strlen($strList) > 0) {
             $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList;
             $DB->Query($strSql, false, $err_mess . __LINE__);
         }
         $DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_supportToCache')");
         $DB->StopUsingMasterOnly();
         //CAgent::AddAgent("CSupportTimetableCache::UpdateDiscardedTickets(" . $currD . ");", "support", "N", 5*60);
     }
     if ($RSD) {
         CTicketReminder::RecalculateSupportDeadline($arFilter);
     }
     return null;
 }
Ejemplo n.º 4
0
 static function ToCache($arFilter = array())
 {
     /*
     $arFilter(
     	SLA => array()
     )
     */
     global $DB;
     $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: ";
     $timetable_cache = self::TIMETABLE_CACHE;
     $ndF = self::GetNumberOfDaysForward();
     $ndB = self::GetNumberOfDaysBackward();
     $currD = time();
     $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60);
     $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60);
     self::$arrS = self::GetShedule($arFilter);
     if (count(self::$arrS) <= 0) {
         return;
     }
     self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter);
     $arrSLA = array_keys(self::$arrS);
     $arSqlSearch = array();
     foreach ($arFilter as $key => $val) {
         if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) {
             continue;
         }
         $key = strtoupper($key);
         if (is_array($val)) {
             $val = implode(" | ", $val);
         }
         switch ($key) {
             case "SLA_ID":
                 $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N");
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__);
     $f = new CSupportTableFields(self::$cache);
     foreach ($arrSLA as $k => $sla) {
         $dateC = $dateF;
         $sum = 0;
         while ($dateC <= $dateT) {
             if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) {
                 $a = self::$arrH[$sla][$dateC];
             } else {
                 $a = self::$arrS[$sla][self::GetDayNom($dateC)];
             }
             foreach ($a as $k2 => $v2) {
                 $sum = $sum + $v2["T"] - $v2["F"];
                 $f->SLA_ID = $sla;
                 $f->DATE_FROM = $dateC + $v2["F"];
                 $f->DATE_TILL = $dateC + $v2["T"];
                 $f->W_TIME = $v2["T"] - $v2["F"];
                 $f->W_TIME_INC = $sum;
                 CTimeZone::Disable();
                 $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__);
                 CTimeZone::Enable();
             }
             $dateC += 24 * 60 * 60;
         }
     }
     CTicketReminder::RecalculateSupportDeadline($arFilter);
 }