1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
holidays.php
См. документацию.
1<?php
2
4
6{
7 static $holidays = array(
8 "ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0, "AUTO_CALCULATED" => true),
9 "NAME" => array("TYPE" => CSupportTableFields::VT_STRING, "DEF_VAL" => "", "MAX_STR_LEN" => 255),
10 "DESCRIPTION" => array("TYPE" => CSupportTableFields::VT_STRING, "DEF_VAL" => "", "MAX_STR_LEN" => 2000),
11 "OPEN_TIME" => array("TYPE" => CSupportTableFields::VT_STRING, "DEF_VAL" => "HOLIDAY", "LIST" => array("HOLIDAY_H", "HOLIDAY", "WORKDAY_H", "WORKDAY_0", "WORKDAY_1", "WORKDAY_2", "WORKDAY_3", "WORKDAY_4", "WORKDAY_5", "WORKDAY_6")),
12 "DATE_FROM" => array("TYPE" => CSupportTableFields::VT_DATE_TIME, "DEF_VAL" => null),
13 "DATE_TILL" => array("TYPE" => CSupportTableFields::VT_DATE_TIME, "DEF_VAL" => null),
14
15 );
16
18 "SLA_ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0),
19 "HOLIDAYS_ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0),
20 );
21 const table = "b_ticket_holidays";
22 const table_s2h = "b_ticket_sla_2_holidays";
23 const table_sla = "b_ticket_sla";
24
25 public static function Set($arFields, $arFieldsSLA) //$arFields, $arFieldsSLA = array(0 => array("HOLIDAYS_ID" => 1, "SLA_ID" => 1), 1 => array("HOLIDAYS_ID" => 2, "SLA_ID" => 2) ...)
26 {
27 global $DB, $APPLICATION;
28
29 $isDemo = null;
30 $isSupportClient = null;
31 $isSupportTeam = null;
32 $isAdmin = null;
33 $isAccess = null;
34 $userID = null;
35 CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID);
36 if(!$isAdmin)
37 {
38 $arMsg = Array();
39 $arMsg[] = array("id"=>"PERMISSION", "text"=> GetMessage("SUP_ERROR_ACCESS_DENIED"));
40 $e = new CAdminException($arMsg);
41 $APPLICATION->ThrowException($e);
42 return false;
43 }
44
45 if(is_array($arFields))
46 {
47 $f = new CSupportTableFields(self::$holidays);
48 $f->FromArray($arFields);
49 }
50 else $f = $arFields;
51 if(is_array($arFieldsSLA))
52 {
53 $f_s = new CSupportTableFields(self::$sla2holidays, CSupportTableFields::C_Table);
54 $f_s->FromTable($arFieldsSLA);
55 }
56 else $f_s = $arFieldsSLA;
57
58
59 $table = self::table;
60 $table_s2h = self::table_s2h;
61
62 $isNew = ($f->ID <= 0);
63
64 $objError = new CAdminException(array());
65 if($f->NAME == '')
66 {
67 $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_NAME')));
68 }
69 if($f->OPEN_TIME == '')
70 {
71 $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_OPEN_TIME')));
72 }
73 $zd = mktime(0, 0, 0, 1, 1, 2010);
74 if($f->DATE_FROM < $zd || $f->DATE_FROM === null || $f->DATE_TILL < $zd || $f->DATE_TILL === null || $f->DATE_FROM > $f->DATE_TILL)
75 {
76 if($f->DATE_FROM < $zd || $f->DATE_FROM === null)
77 {
78 $f->DATE_FROM = time() + CTimeZone::GetOffset();
79 }
80
81 if($f->DATE_TILL < $zd || $f->DATE_TILL === null)
82 {
83 $f->DATE_TILL = time() + CTimeZone::GetOffset();
84 }
85 $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_DATE')));
86 }
87
88 if(count($objError->GetMessages())>0)
89 {
90 $APPLICATION->ThrowException($objError);
91 return false;
92 }
93
94 $arFields_i = $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true);
95 $res = 0;
96 if(count($arFields_i) > 0)
97 {
98 if($isNew)
99 {
100 $res = $DB->Insert($table, $arFields_i);
101 $f->ID = $res;
102 }
103 else
104 {
105 $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $f->ID . "");
106 }
107 }
108
109 if(intval($res) <= 0)
110 {
111 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR'));
112 return false;
113 }
114
115 $DB->Query("DELETE FROM $table_s2h WHERE HOLIDAYS_ID = " . $f->ID);
116 $f_s->ResetNext();
117 while($f_s->Next())
118 {
119 $f_s->HOLIDAYS_ID = $f->ID;
120 if($f_s->SLA_ID > 0)
121 {
122 $strSql = "INSERT INTO " . $table_s2h . "(SLA_ID, HOLIDAYS_ID) VALUES (" . $f_s->SLA_ID . ", " . $f_s->HOLIDAYS_ID . ")";
123 $res = $DB->Query($strSql);
124 }
125 }
126
127 CSupportTimetableCache::toCache(array("SLA_ID"=> $f_s->getColumn("SLA_ID")));
128
129 return $f->ID;
130 }
131
132 // get Holidays list
133 public static function GetList($arSort, $arFilter)
134 {
135 global $DB, $USER, $APPLICATION;
136
137 $filter_keys = array_keys($arFilter);
138 $table = self::table;
139 $table_s2h = self::table_s2h;
140 $arSqlSearch = Array();
141 if(!is_array($arFilter)) $arFilter = Array();
142 foreach($arFilter as $key => $val)
143 {
144 if((is_array($val) && count($val) <= 0) || (!is_array($val) && ((string) $val == '' || $val === 'NOT_REF'))) continue;
145 $key = mb_strtoupper($key);
146 if (is_array($val)) $val = implode(" | ",$val);
147 switch($key)
148 {
149 case "ID":
150 $arSqlSearch[] = GetFilterQuery("H.ID", $val, "N");
151 break;
152 case "~NAME":
153 $arSqlSearch[] = GetFilterQuery("H.NAME", $val, "N");
154 break;
155 case "OPEN_TIME":
156 $arSqlSearch[] = GetFilterQuery("H.OPEN_TIME", $val, "N");
157 break;
158 case "SLA_ID":
159 $arSqlSearch[] = "H.ID IN (
160 SELECT
161 S2H.HOLIDAYS_ID
162 FROM
163 $table_s2h S2H
164 WHERE
165 " . GetFilterQuery("S2H.SLA_ID", $val, "N") . ")";
166 break;
167 case "PERIOD":
168 if(is_array($val) && isset($val["FROM"]) && intval($val["FROM"]) > 0 && isset($val["TILL"]) && intval($val["TILL"]) > 0)
169 {
170 $arSqlSearch[] = "H.DATE_FROM <= " . $DB->CharToDateFunction(GetTime($val["TILL"], "FULL")) . " AND H.DATE_TILL >= " . $DB->CharToDateFunction(GetTime($val["FROM"], "FULL"));
171 }
172 break;
173
174 }
175 }
176
177 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
178
179 $arSort = is_array($arSort) ? $arSort : array();
180 if(count($arSort) > 0)
181 {
182 $ar1 = array_merge($DB->GetTableFieldsList($table), array());
183 $ar2 = array_keys($arSort);
184 $arDiff = array_diff($ar2, $ar1);
185 if(is_array($arDiff) && count($arDiff) > 0) foreach($arDiff as $value) unset($arSort[$value]);
186 }
187 if(count($arSort) <= 0) $arSort = array("ID" => "ASC");
188 $fs = "";
189 foreach($arSort as $by => $order)
190 {
191 if(mb_strtoupper($order) != "DESC") $order="ASC";
192 if($by === "DATE_TILL" || $by === "DATE_FROM")
193 {
194 $fs .= ",
195 " . $by . " " . $by . "_SORT";
196 $arSqlOrder[] = $by . "_SORT " . $order;
197 }
198 else
199 {
200 $arSqlOrder[] = $by . " " . $order;
201 }
202
203 }
204 if(is_array($arSqlOrder) && count($arSqlOrder) > 0) $strSqlOrder = " ORDER BY " . implode(",", $arSqlOrder);
205
206 $strSql = "
207 SELECT
208 H.ID,
209 H.NAME,
210 H.DESCRIPTION,
211 H.OPEN_TIME,
212 " . $DB->DateToCharFunction("H.DATE_FROM", "FULL") . " DATE_FROM,
213 " . $DB->DateToCharFunction("H.DATE_TILL", "FULL") . " DATE_TILL" . $fs . "
214 FROM
215 $table H
216 WHERE
217 $strSqlSearch
218 $strSqlOrder
219 ";
220 $rs = $DB->Query($strSql);
221 return $rs;
222 }
223
224 // get Holidays list
225 public static function GetSLAByID($id, $needObj = false)
226 {
227 global $DB, $USER, $APPLICATION;
228
229 $table_s2h = self::table_s2h;
230 $table_sla = self::table_sla;
231 $id = intval($id);
232
233 $strSql = "
234 SELECT
235 S2H.HOLIDAYS_ID,
236 S2H.SLA_ID,
237 SLA.NAME
238 FROM
239 $table_s2h S2H
240 INNER JOIN $table_sla SLA
241 ON S2H.SLA_ID = SLA.ID
242 AND S2H.HOLIDAYS_ID = $id
243 ORDER BY
244 SLA.NAME
245 ";
246 $res = $DB->Query($strSql);
247 if(!$needObj) return $res;
248 $f_s = new CSupportTableFields(self::$sla2holidays, CSupportTableFields::C_Table);
249 $f_s->RemoveExistingRows();
250 while ($resR = $res->Fetch())
251 {
252 $f_s->AddRow();
253 $f_s->FromArray($resR);
254 }
255 return $f_s;
256 }
257
258 public static function GetOpenTimeArray()
259 {
260 return array(
261 "GB_1" => "SUP_OPEN_TIME_HOLIDAY_G",
262 "HOLIDAY_H" => "SUP_OPEN_TIME_HOLIDAY_H",
263 "HOLIDAY" => "SUP_OPEN_TIME_HOLIDAY",
264 "GE_1" => "",
265 "GB_2" => "SUP_OPEN_TIME_WORKDAY_G",
266 "WORKDAY_H" => "SUP_OPEN_TIME_WORKDAY_H",
267 "WORKDAY_0" => "SUP_OPEN_TIME_WORKDAY_0",
268 "WORKDAY_1" => "SUP_OPEN_TIME_WORKDAY_1",
269 "WORKDAY_2" => "SUP_OPEN_TIME_WORKDAY_2",
270 "WORKDAY_3" => "SUP_OPEN_TIME_WORKDAY_3",
271 "WORKDAY_4" => "SUP_OPEN_TIME_WORKDAY_4",
272 "WORKDAY_5" => "SUP_OPEN_TIME_WORKDAY_5",
273 "WORKDAY_6" => "SUP_OPEN_TIME_WORKDAY_6",
274 "GE_2" => "",
275 );
276
277 }
278
279 public static function GetOpenTimeT($v)
280 {
282 return (isset($arr[$v]) ? $arr[$v] : "");
283 }
284
285 // delete Holiday
286 public static function Delete($id, $checkRights=true)
287 {
288 global $DB, $USER, $APPLICATION;
289 $id = intval($id);
290 $table = self::table;
291 $table_s2h = self::table_s2h;
292
293 if ($id <= 0) return false;
294
295 $isDemo = null;
296 $isSupportClient = null;
297 $isSupportTeam = null;
298 $isAdmin = null;
299 $isAccess = null;
300 $userID = null;
301
302 CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights);
303
304 if(!$isAdmin)
305 {
306 $arMsg = Array();
307 $arMsg[] = array("id"=>"PERMISSION", "text"=> GetMessage("SUP_ERROR_ACCESS_DENIED"));
308 $e = new CAdminException($arMsg);
309 $APPLICATION->ThrowException($e);
310 return false;
311 }
312
313 // get affected sla
314 $affected_sla = array();
315
316 $res = $DB->Query("SELECT SLA_ID FROM b_ticket_sla_2_holidays WHERE HOLIDAYS_ID = $id");
317 while ($row = $res->Fetch())
318 {
319 $affected_sla[] = $row['SLA_ID'];
320 }
321
322 // delete
323 $DB->Query("DELETE FROM $table WHERE ID = $id");
324 $DB->Query("DELETE FROM $table_s2h WHERE HOLIDAYS_ID = $id");
325
326 // recalculate only affected sla
327 CSupportTimetableCache::toCache(array("SLA_ID" => $affected_sla));
328
329 return true;
330 }
331}
global $APPLICATION
Определения include.php:80
static GetRoles(&$isDemo, &$isSupportClient, &$isSupportTeam, &$isAdmin, &$isAccess, &$userID, $checkRights=true)
Определения support.php:142
Определения holidays.php:6
static Delete($id, $checkRights=true)
Определения holidays.php:286
const table
Определения holidays.php:21
static GetOpenTimeArray()
Определения holidays.php:258
const table_sla
Определения holidays.php:23
const table_s2h
Определения holidays.php:22
static GetSLAByID($id, $needObj=false)
Определения holidays.php:225
static $holidays
Определения holidays.php:7
static GetOpenTimeT($v)
Определения holidays.php:279
static Set($arFields, $arFieldsSLA)
Определения holidays.php:25
static GetList($arSort, $arFilter)
Определения holidays.php:133
static $sla2holidays
Определения holidays.php:17
const NOT_NULL
Определения tablefields.php:22
const VT_NUMBER
Определения tablefields.php:5
const C_Table
Определения tablefields.php:31
const ALL
Определения tablefields.php:28
const VT_STRING
Определения tablefields.php:6
const VT_DATE_TIME
Определения tablefields.php:10
$f
Определения component_props.php:52
$arFields
Определения dblapprove.php:5
$arr
Определения file_new.php:624
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
GetFilterSqlSearch($arSqlSearch=array(), $FilterLogic="FILTER_logic")
Определения filter_tools.php:397
GetFilterQuery($field, $val, $procent="Y", $ex_sep=array(), $clob="N", $div_fields="Y", $clob_upper="N")
Определения filter_tools.php:383
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
GetTime($timestamp, $type="SHORT", $site=false, $bSearchInSitesOnly=false)
Определения tools.php:1890
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$order
Определения payment.php:8
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106