• Модуль: support
  • Путь к файлу: ~/bitrix/modules/support/classes/general/timetable.php
  • Класс: CSupportTimetable
  • Вызов: CSupportTimetable::Set
static function Set($arFields, $arFieldsShedule) //$arFields, $arFieldsShedule = array(0 => array("ID" => 1 ...), 1 => array("ID" => 3 ...) ...)
{
	global $DB, $APPLICATION;
	$err_mess = (self::err_mess())."
Function: Set
Line: "; $isDemo = null; $isSupportClient = null; $isSupportTeam = null; $isAdmin = null; $isAccess = null; $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID); if(!$isAdmin) { $arMsg = Array(); $arMsg[] = array("id"=>"PERMISSION", "text"=> GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); return false; } if(is_array($arFields)) { $f = new CSupportTableFields(self::$fieldsTypes); $f->FromArray($arFields); } else $f = $arFields; if(is_array($arFieldsShedule)) { $f_s = new CSupportTableFields(self::$fieldsTypesShedule, CSupportTableFields::C_Table); $f_s->FromTable($arFieldsShedule); } else $f_s = $arFieldsShedule; $table = self::TABLE; $table_shedule = self::TABLE_SHEDULE; $id = $f->ID; $isNew = ($f->ID <= 0); if($f->NAME == '') { $APPLICATION->ThrowException(GetMessage('SUP_ERROR_EMPTY_NAME')); return false; } $arFields_i = $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL,CSupportTableFields::NOT_DEFAULT), true); $res = 0; if(count($arFields_i) > 0) { if($isNew) { $res = $DB->Insert($table, $arFields_i, $err_mess . __LINE__); } else { $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $id . "", $err_mess . __LINE__); } } if(intval($res) <= 0) { $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR')); return false; } if($isNew) { $id = $res; } $DB->Query("DELETE FROM $table_shedule WHERE TIMETABLE_ID = $id", false, $err_mess . __LINE__); $noWrite = array(); $f_s->ResetNext(); while($f_s->Next()) { $f_s->TIMETABLE_ID = $id; if (isset($noWrite[$f_s->WEEKDAY_NUMBER]) && ($noWrite[$f_s->WEEKDAY_NUMBER] != "CUSTOM" || $f_s->OPEN_TIME != "CUSTOM") ) { continue; } if($f_s->OPEN_TIME == "CUSTOM" && $f_s->MINUTE_FROM <= 0 && $f_s->MINUTE_TILL <= 0) { continue; } $DB->Insert($table_shedule, $f_s->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__); $noWrite[$f_s->WEEKDAY_NUMBER] = $f_s->OPEN_TIME; } for($i = 0; $i <= 6; $i++) { $a = array( "SLA_ID" => 0, "TIMETABLE_ID" => intval($id), "WEEKDAY_NUMBER" => intval($i), "OPEN_TIME" => "'CLOSED'", "MINUTE_FROM" => null, "MINUTE_TILL" => null ); if (!isset($noWrite[$i])) { $DB->Insert($table_shedule, $a, $err_mess . __LINE__); } } // recalculate only affected sla $affected_sla = array(); $res = $DB->Query("SELECT ID FROM b_ticket_sla WHERE TIMETABLE_ID = $id"); while ($row = $res->Fetch()) { $affected_sla[] = $row['ID']; } CSupportTimetableCache::toCache(array('SLA_ID' => $affected_sla)); return $id; }