Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accesseventhandler.php
1<?php
2
3
5
6
11
13{
14 public static function onBeforeIBlockSectionUpdate(&$fields)
15 {
16 if (
17 !is_array($fields)
18 || !array_key_exists('IBLOCK_ID', $fields)
19 || !array_key_exists('UF_HEAD', $fields)
20 || !array_key_exists('ID', $fields)
21 )
22 {
23 return;
24 }
25
26 $iblockId = (int) \COption::GetOptionInt('intranet', 'iblock_structure');
27 if (
28 !$iblockId
29 || (int) $fields['IBLOCK_ID'] !== $iblockId
30 )
31 {
32 return;
33 }
34
35 $ufHead = (int) $fields['UF_HEAD'];
36 if ($ufHead > 0)
37 {
38 (new AccessAuthProvider())->DeleteByUser($ufHead);
39 }
40
41 $accessCode = AccessCode::ACCESS_DIRECTOR . $fields['ID'];
42 self::deleteByAccessCode($accessCode);
43 }
44
45 public static function onBeforeIBlockSectionDelete($sectionId)
46 {
47 $sectionId = (int) $sectionId;
48 if ($sectionId < 1)
49 {
50 return;
51 }
52
53 $iblockId = (int) \COption::GetOptionInt('intranet', 'iblock_structure');
54 if (!$iblockId)
55 {
56 return;
57 }
58
59 if (!Loader::includeModule('iblock'))
60 {
61 return;
62 }
63
64 $res = SectionTable::getList([
65 'filter' => [
66 '=IBLOCK_ID' => $iblockId,
67 '=ID' => $sectionId
68 ]
69 ]);
70 if(!$res->getSelectedRowsCount())
71 {
72 return;
73 }
74
75 $accessCode = AccessCode::ACCESS_DIRECTOR . $sectionId;
76 self::deleteByAccessCode($accessCode);
77 }
78
79 public static function onBeforeIBlockSectionAdd(&$fields)
80 {
81 if (
82 !is_array($fields)
83 || !array_key_exists('IBLOCK_ID', $fields)
84 || !array_key_exists('UF_HEAD', $fields)
85 || !array_key_exists('IBLOCK_SECTION_ID', $fields)
86 )
87 {
88 return;
89 }
90
91 $ufHead = (int) $fields['UF_HEAD'];
92 if ($ufHead < 1)
93 {
94 return;
95 }
96 (new AccessAuthProvider())->DeleteByUser($ufHead);
97 }
98
99 private static function deleteByAccessCode(string $accessCode)
100 {
101 // find users by access codes
102 $res = UserAccessTable::getList([
103 'filter' => [
104 '=ACCESS_CODE' => $accessCode
105 ],
106 'select' => ['USER_ID']
107 ]);
108
109 $provider = new AccessAuthProvider();
110 while ($row = $res->fetch())
111 {
112 $provider->DeleteByUser($row['USER_ID']);
113 }
114 }
115}
static includeModule($moduleName)
Definition loader.php:69