1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calendar_type.php
См. документацию.
1<?
2
9
11{
12 public const OPERATION_VIEW = 'calendar_type_view';
13 public const OPERATION_ADD = 'calendar_type_add';
14 public const OPERATION_EDIT = 'calendar_type_edit';
15 public const OPERATION_EDIT_SECTION = 'calendar_type_edit_section';
16 public const OPERATION_EDIT_ACCESS = 'calendar_type_edit_access';
17 private static
18 $Permissions = [],
19 $arOp = [],
20 $userOperationsCache = [];
21
22 public static function GetList($params = [])
23 {
24 global $DB;
25 $access = new CAccess();
26 $access->UpdateCodes();
27 $arFilter = $params['arFilter'] ?? null;
28 $result = false;
29 $cacheId = false;
30 $cachePath = '';
31 $arOrder = $params['arOrder'] ?? Array('XML_ID' => 'asc');
32 $checkPermissions = ($params['checkPermissions'] ?? true) !== false;
33
34 $bCache = CCalendar::CacheTime() > 0;
35
36 if ($bCache)
37 {
38 $cache = new CPHPCache;
39 $cacheId = serialize(array('type_list', $arFilter, $arOrder));
40 $cachePath = CCalendar::CachePath().'type_list';
41
42 if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath))
43 {
44 $res = $cache->GetVars();
45 $result = $res["arResult"];
46 $arTypeXmlIds = $res["arTypeXmlIds"];
47 }
48 }
49
50 if (!$bCache || !isset($arTypeXmlIds))
51 {
52 $arFields = [
53 "XML_ID" => ["FIELD_NAME" => "CT.XML_ID", "FIELD_TYPE" => "string"],
54 "NAME" => ["FIELD_NAME" => "CT.NAME", "FIELD_TYPE" => "string"],
55 "ACTIVE" => ["FIELD_NAME" => "CT.ACTIVE", "FIELD_TYPE" => "string"],
56 "DESCRIPTION" => ["FIELD_NAME" => "CT.DESCRIPTION", "FIELD_TYPE" => "string"],
57 "EXTERNAL_ID" => ["FIELD_NAME" => "CT.EXTERNAL_ID", "FIELD_TYPE" => "string"]
58 ];
59
60 $arSqlSearch = [];
61 if(is_array($arFilter))
62 {
63 $filter_keys = array_keys($arFilter);
64 foreach ($filter_keys as $i => $value)
65 {
66 $n = mb_strtoupper($value);
67 $val = $arFilter[$value];
68
69 if (is_string($val) && !$val)
70 {
71 continue;
72 }
73
74 if ($n === 'XML_ID')
75 {
76 if (is_array($val))
77 {
78 $strXml = "";
79 foreach($val as $xmlId)
80 {
81 $strXml .= ",'" . $DB->ForSql($xmlId) . "'";
82 }
83 $arSqlSearch[] = "CT.XML_ID in (".trim($strXml, ", ").")";
84 }
85 else
86 {
87 $arSqlSearch[] = GetFilterQuery("CT.XML_ID", $val, 'N');
88 }
89 }
90 if ($n === 'EXTERNAL_ID')
91 {
92 $arSqlSearch[] = GetFilterQuery("CT.EXTERNAL_ID", $val, 'N');
93 }
94 elseif (isset($arFields[$n]))
95 {
96 $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val);
97 }
98 }
99 }
100
101 $strOrderBy = '';
102 foreach($arOrder as $by=>$order)
103 {
104 if (isset($arFields[mb_strtoupper($by)]))
105 {
106 $strOrderBy .= $arFields[mb_strtoupper($by)]["FIELD_NAME"] . ' '
107 . (mb_strtolower($order) === 'desc' ? 'desc' : 'asc') . ',';
108 }
109 }
110
111 if ($strOrderBy)
112 {
113 $strOrderBy = "ORDER BY " . rtrim($strOrderBy, ",");
114 }
115
116 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
117
118 $strSql = "
119 SELECT
120 CT.*
121 FROM
122 b_calendar_type CT
123 WHERE
124 $strSqlSearch
125 $strOrderBy";
126
127 $res = $DB->Query($strSql);
128 $result = [];
129 $arTypeXmlIds = [];
130 while($arRes = $res->Fetch())
131 {
132 $result[] = $arRes;
133 $arTypeXmlIds[] = $arRes['XML_ID'];
134 }
135
136 if ($bCache && isset($cache))
137 {
138 $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath);
139 $cache->EndDataCache(array(
140 "arResult" => $result,
141 "arTypeXmlIds" => $arTypeXmlIds
142 ));
143 }
144 }
145
146 if ($checkPermissions && !empty($arTypeXmlIds))
147 {
148 $arPerm = self::GetArrayPermissions($arTypeXmlIds);
149 $res = [];
150 $arAccessCodes = [];
151 $accessController = new TypeAccessController(CCalendar::GetCurUserId());
152
153 if (is_array($result))
154 {
155 foreach($result as $type)
156 {
157 $typeXmlId = $type['XML_ID'];
158 $typeModel = TypeModel::createFromXmlId($typeXmlId);
159 $request = [
160 ActionDictionary::ACTION_TYPE_VIEW => [],
161 ActionDictionary::ACTION_TYPE_EDIT => [],
162 ActionDictionary::ACTION_TYPE_ACCESS => [],
163 ];
164
165 $result = $accessController->batchCheck($request, $typeModel);
166 if ($result[ActionDictionary::ACTION_TYPE_VIEW])
167 {
168 $type['PERM'] = [
169 'view' => true,
170 'add' => $result[ActionDictionary::ACTION_TYPE_EDIT],
171 'edit' => $result[ActionDictionary::ACTION_TYPE_EDIT],
172 'edit_section' => $result[ActionDictionary::ACTION_TYPE_EDIT],
173 'access' => $result[ActionDictionary::ACTION_TYPE_ACCESS],
174 ];
175
176 if ($result[ActionDictionary::ACTION_TYPE_ACCESS])
177 {
178 $type['ACCESS'] = [];
179 if (!empty($arPerm[$typeXmlId]))
180 {
181 // Add codes to get they full names for interface
182 $currentAccessCodes = array_keys($arPerm[$typeXmlId]);
183 foreach ($currentAccessCodes as $code)
184 {
185 if (!in_array($code, $arAccessCodes, true))
186 {
187 $arAccessCodes[] = $code;
188 }
189 }
190 $type['ACCESS'] = $arPerm[$typeXmlId];
191 }
192 }
193 $res[] = $type;
194 }
195 }
196 }
197
198 CCalendar::PushAccessNames($arAccessCodes);
199 $result = $res;
200 }
201
202 return $result;
203 }
204
205 public static function Edit($params)
206 {
207 global $DB;
208 $arFields = $params['arFields'];
209 $XML_ID = preg_replace("/[^a-zA-Z0-9_]/i", "", $arFields['XML_ID']);
210 $arFields['XML_ID'] = $XML_ID;
211 if (!isset($arFields['XML_ID']) || $XML_ID == "")
212 {
213 return false;
214 }
215
216 //return $APPLICATION->ThrowException(GetMessage("EC_ACCESS_DENIED"));
217
218 $access = $arFields['ACCESS'] ?? null;
219 unset($arFields['ACCESS']);
220
221 if (count($arFields) > 1) // We have not only XML_ID
222 {
223 if ($params['NEW']) // Add
224 {
225 $strSql = "SELECT * FROM b_calendar_type WHERE XML_ID='".$DB->ForSql($XML_ID)."'";
226 $res = $DB->Query($strSql);
227 if (!($arRes = $res->Fetch()))
228 {
229 $arInsert = $DB->PrepareInsert("b_calendar_type", $arFields);
230 $strSql ="INSERT INTO b_calendar_type(".$arInsert[0].") VALUES(".$arInsert[1].")";
231 $DB->Query($strSql);
232 }
233 else
234 {
235 false;
236 }
237 }
238 else // Update
239 {
240 unset($arFields['XML_ID']);
241 if (!empty($arFields))
242 {
243 $strUpdate = $DB->PrepareUpdate("b_calendar_type", $arFields);
244 $strSql =
245 "UPDATE b_calendar_type SET ".
246 $strUpdate.
247 " WHERE XML_ID='".$DB->ForSql($XML_ID)."'";
248 $DB->QueryBind($strSql, array('DESCRIPTION' => $arFields['DESCRIPTION']));
249 }
250 }
251 }
252
253 //SaveAccess
254 $accessController = new TypeAccessController(CCalendar::GetUserId());
255 $typeModel = TypeModel::createFromXmlId($arFields['XML_ID']);
256
257 if (is_array($access) && $accessController->check(ActionDictionary::ACTION_TYPE_ACCESS, $typeModel))
258 {
259 self::SavePermissions($XML_ID, $access);
260 }
261
262 CCalendar::ClearCache('type_list');
263 return $XML_ID;
264 }
265
266 public static function Delete($XML_ID)
267 {
268 global $DB;
269 // Del types
270 $DB->Query("DELETE FROM b_calendar_type WHERE XML_ID='".$DB->ForSql($XML_ID)."'");
271
272 // Del access for types
273 $DB->Query("DELETE FROM b_calendar_access WHERE SECT_ID='".$DB->ForSql($XML_ID)."'");
274
275 // Del sections
276 $DB->Query("DELETE FROM b_calendar_section WHERE CAL_TYPE='".$DB->ForSql($XML_ID)."'");
277
278 // Del events
279 $DB->Query("DELETE FROM b_calendar_event WHERE CAL_TYPE='".$DB->ForSql($XML_ID)."'");
280
281 CCalendar::ClearCache(array('type_list', 'section_list', 'event_list'));
282
283 return true;
284 }
285
286 public static function SavePermissions($type, $taskPerm)
287 {
288 global $DB;
289 $DB->Query("DELETE FROM b_calendar_access WHERE SECT_ID='".$DB->ForSql($type)."'");
290
291 if (is_array($taskPerm))
292 {
293 foreach ($taskPerm as $accessCode => $taskId)
294 {
295 if (0 === strpos($accessCode, "SG"))
296 {
297 $accessCode = self::prepareGroupCode($accessCode);
298 }
299
300 $insert = $DB->PrepareInsert(
301 "b_calendar_access",
302 [
303 "ACCESS_CODE" => $accessCode,
304 "TASK_ID" => (int)$taskId,
305 "SECT_ID" => $type
306 ]
307 );
308
309 $strSql = "INSERT INTO b_calendar_access(" . $insert[0] . ") VALUES(" . $insert[1] . ")";
310 $DB->Query($strSql);
311 }
312 }
313 }
314
315 private static function prepareGroupCode($code)
316 {
317 $parsedCode = explode('_', $code);
318
319 if (count($parsedCode) === 1)
320 {
321 $code .= '_K';
322 }
323
324 return $code;
325 }
326
327
328 public static function GetArrayPermissions($arTypes = [])
329 {
330 $sqlHelper = $connection = \Bitrix\Main\Application::getConnection()->getSqlHelper();
331 $arTypes = array_map(static function($type) use ($sqlHelper) {
332 return $sqlHelper->forSql($type);
333 }, $arTypes);
334
336 ->setSelect(['*'])
337 ->whereIn('SECT_ID', $arTypes)
338 ->exec()
339 ;
340
341 while ($res = $query->fetch())
342 {
343 $xmlId = $res['SECT_ID'];
344 if (!isset(self::$Permissions[$xmlId]) || !is_array(self::$Permissions[$xmlId]))
345 {
346 self::$Permissions[$xmlId] = [];
347 }
348 self::$Permissions[$xmlId][$res['ACCESS_CODE']] = $res['TASK_ID'];
349 }
350 foreach ($arTypes as $type)
351 {
352 if (!isset(self::$Permissions[$type]))
353 {
354 self::$Permissions[$type] = [];
355 }
356 }
357
358 return self::$Permissions;
359 }
360
361 public static function CanDo($operation, $xmlId = 0, $userId = null)
362 {
363 global $USER;
364 if ((!$USER || !is_object($USER)) || $USER->CanDoOperation('edit_php'))
365 {
366 return true;
367 }
368
369 if (!(int)$userId)
370 {
371 $userId = CCalendar::GetCurUserId();
372 }
373
374 if (
375 CCalendar::IsBitrix24()
376 && Loader::includeModule('bitrix24')
377 && \CBitrix24::isPortalAdmin($userId)
378 )
379 {
380 return true;
381 }
382
383 if (
384 ($xmlId === 'group' || $xmlId === 'user' || CCalendar::IsBitrix24())
385 && CCalendar::IsSocNet()
386 && CCalendar::IsSocnetAdmin()
387 )
388 {
389 return true;
390 }
391
392 return in_array($operation, self::GetOperations($xmlId, $userId), true);
393 }
394
395 public static function GetOperations($xmlId, $userId = null)
396 {
397 global $USER;
398 if (!$userId)
399 {
400 $userId = CCalendar::GetCurUserId();
401 }
402
403 $opCacheKey = $xmlId.'_'.$userId;
404
405 if (isset(self::$userOperationsCache[$opCacheKey]) && is_array(self::$userOperationsCache[$opCacheKey]))
406 {
407 $result = self::$userOperationsCache[$opCacheKey];
408 }
409 else
410 {
411 $arCodes = [];
412 if ($userId)
413 {
414 $arCodes = Util::getUserAccessCodes($userId);
415 }
416
417 if(!in_array('G2', $arCodes, true))
418 {
419 $arCodes[] = 'G2';
420 }
421
422 if($userId && !in_array('AU', $arCodes, true) && (int)$USER->GetId() === (int)$userId)
423 {
424 $arCodes[] = 'AU';
425 }
426
427 if($userId && !in_array('UA', $arCodes, true) && (int)$USER->GetId() === (int)$userId)
428 {
429 $arCodes[] = 'UA';
430 }
431
432 $key = $xmlId.'|'.implode(',', $arCodes);
433 if(!isset(self::$arOp[$key]) || !is_array(self::$arOp[$key]))
434 {
435 if(!isset(self::$Permissions[$xmlId]))
436 {
437 self::GetArrayPermissions([$xmlId]);
438 }
439 $perms = self::$Permissions[$xmlId];
440
441 self::$arOp[$key] = [];
442 if(is_array($perms))
443 {
444 foreach($perms as $code => $taskId)
445 {
446 if (in_array($code, $arCodes, true))
447 {
448 self::$arOp[$key] = array_merge(self::$arOp[$key], CTask::GetOperations($taskId, true));
449 }
450 }
451 }
452 }
453 $result = self::$userOperationsCache[$opCacheKey] = self::$arOp[$key];
454 }
455
456 return $result;
457 }
458}
459?>
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
$arTypes
Определения options.php:23
$accessController
Определения options.php:23
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения util.php:21
static getConnection($name="")
Определения application.php:638
Определения loader.php:13
Определения user.php:48
Определения access.php:15
static GetOperations($ID, $return_names=false)
Определения task.php:230
Определения calendar_type.php:11
static GetOperations($xmlId, $userId=null)
Определения calendar_type.php:395
const OPERATION_EDIT_SECTION
Определения calendar_type.php:15
static Edit($params)
Определения calendar_type.php:205
const OPERATION_EDIT
Определения calendar_type.php:14
static GetArrayPermissions($arTypes=[])
Определения calendar_type.php:328
static Delete($XML_ID)
Определения calendar_type.php:266
static GetList($params=[])
Определения calendar_type.php:22
static SavePermissions($type, $taskPerm)
Определения calendar_type.php:286
const OPERATION_ADD
Определения calendar_type.php:13
const OPERATION_VIEW
Определения calendar_type.php:12
static CanDo($operation, $xmlId=0, $userId=null)
Определения calendar_type.php:361
const OPERATION_EDIT_ACCESS
Определения calendar_type.php:16
Определения cache.php:11
$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
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
$arCodes
Определения options.php:154
$order
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$val
Определения options.php:1793
$arRes
Определения options.php:104
$n
Определения update_log.php:107
$arFilter
Определения user_search.php:106