1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
timetable.php
См. документацию.
1<?php
2
4
6{
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 );
13 "ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0, "AUTO_CALCULATED" => true),
14 "SLA_ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0),
15 "TIMETABLE_ID" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => null),
16 "WEEKDAY_NUMBER" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => 0),
17 "OPEN_TIME" => array("TYPE" => CSupportTableFields::VT_STRING, "DEF_VAL" => "24H", "LIST" => array("24H", "CLOSED", "CUSTOM")),
18 "MINUTE_FROM" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => null),
19 "MINUTE_TILL" => array("TYPE" => CSupportTableFields::VT_NUMBER, "DEF_VAL" => null),
20
21 );
22 const TABLE = "b_ticket_timetable";
23 const TABLE_SHEDULE = "b_ticket_sla_shedule";
24
25 public static function Set($arFields, $arFieldsShedule) //$arFields, $arFieldsShedule = array(0 => array("ID" => 1 ...), 1 => array("ID" => 3 ...) ...)
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::$fieldsTypes);
48 $f->FromArray($arFields);
49 }
50 else $f = $arFields;
51 if(is_array($arFieldsShedule))
52 {
53 $f_s = new CSupportTableFields(self::$fieldsTypesShedule, CSupportTableFields::C_Table);
54 $f_s->FromTable($arFieldsShedule);
55 }
56 else $f_s = $arFieldsShedule;
57
58 $table = self::TABLE;
59 $table_shedule = self::TABLE_SHEDULE;
60
61 $id = $f->ID;
62 $isNew = ($f->ID <= 0);
63
64 if($f->NAME == '')
65 {
66 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_EMPTY_NAME'));
67 return false;
68 }
69
71 $res = 0;
72 if(count($arFields_i) > 0)
73 {
74 if($isNew)
75 {
76 $res = $DB->Insert($table, $arFields_i);
77 }
78 else
79 {
80 $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $id . "");
81 }
82 }
83
84 if(intval($res) <= 0)
85 {
86 $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR'));
87 return false;
88 }
89 if($isNew)
90 {
91 $id = $res;
92 }
93
94 $DB->Query("DELETE FROM $table_shedule WHERE TIMETABLE_ID = $id");
95 $noWrite = array();
96 $f_s->ResetNext();
97 while($f_s->Next())
98 {
99 $f_s->TIMETABLE_ID = $id;
100 if (isset($noWrite[$f_s->WEEKDAY_NUMBER]) && ($noWrite[$f_s->WEEKDAY_NUMBER] != "CUSTOM" || $f_s->OPEN_TIME != "CUSTOM") )
101 {
102 continue;
103 }
104 if($f_s->OPEN_TIME == "CUSTOM" && $f_s->MINUTE_FROM <= 0 && $f_s->MINUTE_TILL <= 0)
105 {
106 continue;
107 }
108 $DB->Insert($table_shedule, $f_s->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true));
109 $noWrite[$f_s->WEEKDAY_NUMBER] = $f_s->OPEN_TIME;
110 }
111 for($i = 0; $i <= 6; $i++)
112 {
113 $a = array(
114 "SLA_ID" => 0,
115 "TIMETABLE_ID" => intval($id),
116 "WEEKDAY_NUMBER" => intval($i),
117 "OPEN_TIME" => "'CLOSED'",
118 "MINUTE_FROM" => null,
119 "MINUTE_TILL" => null
120 );
121 if (!isset($noWrite[$i]))
122 {
123 $DB->Insert($table_shedule, $a);
124 }
125 }
126
127 // recalculate only affected sla
128 $affected_sla = array();
129
130 $res = $DB->Query("SELECT ID FROM b_ticket_sla WHERE TIMETABLE_ID = $id");
131 while ($row = $res->Fetch())
132 {
133 $affected_sla[] = $row['ID'];
134 }
135
136 CSupportTimetableCache::toCache(array('SLA_ID' => $affected_sla));
137
138 return $id;
139 }
140
141 // get Timetable list
142 public static function GetList($arSort = null, $arFilter = null)
143 {
144 global $DB, $USER, $APPLICATION;
145 $table = self::TABLE;
146 $arSqlSearch = Array();
147 if(!is_array($arFilter))
148 {
149 $arFilter = Array();
150 }
151 foreach($arFilter as $key => $val)
152 {
153 if((is_array($val) && count($val) <= 0) || (!is_array($val) && ((string) $val == '' || $val === 'NOT_REF')))
154 {
155 continue;
156 }
157 $key = mb_strtoupper($key);
158 if (is_array($val))
159 {
160 $val = implode(" | ",$val);
161 }
162 switch($key)
163 {
164 case "ID":
165 $arSqlSearch[] = GetFilterQuery("T.ID", $val, "N");
166 break;
167 case "~NAME":
168 //case "DESCRIPTION":
169 $arSqlSearch[] = GetFilterQuery("T.NAME", $val, "N");
170 break;
171 }
172 }
173
174 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
175
176 $arSort = is_array($arSort) ? $arSort : array();
177 if(isset($arSort["DESCRIPTION"]))
178 {
179 unset($arSort["DESCRIPTION"]);
180 }
181 if(count($arSort) > 0)
182 {
183 $ar1 = array_merge($DB->GetTableFieldsList($table), array());
184 $ar2 = array_keys($arSort);
185 $arDiff = array_diff($ar2, $ar1);
186 if(is_array($arDiff) && count($arDiff) > 0) foreach($arDiff as $value) unset($arSort[$value]);
187 }
188 if(count($arSort) <= 0)
189 {
190 $arSort = array("ID" => "asc");
191 }
192 foreach($arSort as $by => $order)
193 {
194 if(mb_strtoupper($order) != "DESC")
195 {
196 $order="ASC";
197 }
198 $arSqlOrder[] = $by . " " . $order;
199 }
200 if(is_array($arSqlOrder) && count($arSqlOrder) > 0)
201 {
202 $strSqlOrder = " ORDER BY " . implode(",", $arSqlOrder);
203 }
204
205 $strSql = "
206 SELECT
207 T.*
208 FROM
209 $table T
210 WHERE
211 $strSqlSearch
212 $strSqlOrder
213 ";
214 $rs = $DB->Query($strSql);
215 return $rs;
216 }
217
218 public static function GetSheduleByID($id, $needObj = false)
219 {
220 global $DB;
221 $tableShedule = self::TABLE_SHEDULE;
222 $id = intval($id);
223
224 $strSql = "
225 SELECT
226 T.*
227 FROM
228 $tableShedule T
229 WHERE
230 T.TIMETABLE_ID = $id
231 ";
232 $res = $DB->Query($strSql);
233 if(!$needObj)
234 {
235 return $res;
236 }
237 $f_s = new CSupportTableFields(self::$fieldsTypesShedule, CSupportTableFields::C_Table);
238 $f_s->RemoveExistingRows();
239 while ($resR = $res->Fetch())
240 {
241 $f_s->AddRow();
242 $f_s->FromArray($resR);
243 }
244 return $f_s;
245 }
246
247 // delete Timetable
248 public static function Delete($id, $checkRights=true)
249 {
250 global $DB, $USER, $APPLICATION;
251 $id = intval($id);
252 $table = self::TABLE;
253 $tableShedule = self::TABLE_SHEDULE;
254
255 if($id <= 0)
256 {
257 return false;
258 }
259
260 $isDemo = null;
261 $isSupportClient = null;
262 $isSupportTeam = null;
263 $isAdmin = null;
264 $isAccess = null;
265 $userID = null;
266 CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights);
267
268 if(!$isAdmin)
269 {
270 $arMsg = Array();
271 $arMsg[] = array("id"=>"PERMISSION", "text"=> GetMessage("SUP_ERROR_ACCESS_DENIED"));
272 $e = new CAdminException($arMsg);
273 $APPLICATION->ThrowException($e);
274 return false;
275 }
276
277
278 $strSql = "SELECT DISTINCT 'x' FROM b_ticket_sla WHERE TIMETABLE_ID = $id";
279 $rs = $DB->Query($strSql);
280 if (!$rs->Fetch())
281 {
282 $DB->Query("DELETE FROM $table WHERE ID = $id");
283 $DB->Query("DELETE FROM $tableShedule WHERE TIMETABLE_ID = $id");
284 return true;
285 }
286 else
287 $APPLICATION->ThrowException(str_replace("#ID#", "$id", GetMessage("SUP_ERROR_TIMETABLE_HAS_SLA")));
288
289 return false;
290 }
291}
global $APPLICATION
Определения include.php:80
static GetRoles(&$isDemo, &$isSupportClient, &$isSupportTeam, &$isAdmin, &$isAccess, &$userID, $checkRights=true)
Определения support.php:142
const NOT_NULL
Определения tablefields.php:22
const NOT_DEFAULT
Определения tablefields.php:23
const VT_NUMBER
Определения tablefields.php:5
const C_Table
Определения tablefields.php:31
const ALL
Определения tablefields.php:28
const VT_STRING
Определения tablefields.php:6
Определения timetable.php:6
static Delete($id, $checkRights=true)
Определения timetable.php:248
static $fieldsTypesShedule
Определения timetable.php:12
static Set($arFields, $arFieldsShedule)
Определения timetable.php:25
static GetList($arSort=null, $arFilter=null)
Определения timetable.php:142
static GetSheduleByID($id, $needObj=false)
Определения timetable.php:218
const TABLE_SHEDULE
Определения timetable.php:23
const TABLE
Определения timetable.php:22
static $fieldsTypes
Определения timetable.php:7
$f
Определения component_props.php:52
$arFields
Определения dblapprove.php:5
</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
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
$i
Определения factura.php:643
</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
else $a
Определения template.php:137
$val
Определения options.php:1793
$rs
Определения action.php:82
$arFilter
Определения user_search.php:106