Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accesseventhandler.php
1
<?php
2
3
4
namespace
Bitrix\Main\Access\Auth
;
5
6
7
use
Bitrix\Iblock\SectionTable
;
8
use
Bitrix\Main\Access\AccessCode
;
9
use
Bitrix\Main\Loader
;
10
use
Bitrix\Main\UserAccessTable
;
11
12
class
AccessEventHandler
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
}
Bitrix\Iblock\SectionTable
Definition
sectiontable.php:61
Bitrix\Main\Access\AccessCode
Definition
accesscode.php:13
Bitrix\Main\Access\AccessCode\ACCESS_DIRECTOR
const ACCESS_DIRECTOR
Definition
accesscode.php:15
Bitrix\Main\Access\Auth\AccessAuthProvider
Definition
accessauthprovider.php:9
Bitrix\Main\Access\Auth\AccessEventHandler
Definition
accesseventhandler.php:13
Bitrix\Main\Access\Auth\AccessEventHandler\onBeforeIBlockSectionDelete
static onBeforeIBlockSectionDelete($sectionId)
Definition
accesseventhandler.php:45
Bitrix\Main\Access\Auth\AccessEventHandler\onBeforeIBlockSectionUpdate
static onBeforeIBlockSectionUpdate(&$fields)
Definition
accesseventhandler.php:14
Bitrix\Main\Access\Auth\AccessEventHandler\onBeforeIBlockSectionAdd
static onBeforeIBlockSectionAdd(&$fields)
Definition
accesseventhandler.php:79
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Definition
loader.php:69
Bitrix\Main\UserAccessTable
Definition
useraccess.php:24
Bitrix\Main\Access\Auth
Definition
accessauthprovider.php:3
modules
main
lib
access
auth
accesseventhandler.php
Создано системой
1.10.0