Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
componenthelper.php
1<?php
9
12
14{
15 private static $cachedResult = [];
16
17 public static function getForumPermission(array $params = []): ?string
18 {
19 global $USER;
20 $currentUserId = $USER->getId();
21 $isCurrentUserAdmin = \CSocNetUser::isCurrentUserModuleAdmin();
22 $entityType = ($params['ENTITY_TYPE'] ?? SONET_ENTITY_USER);
23 $entityId = (int)($params['ENTITY_ID'] ?? 0);
24
25 $result = null;
26
27 if (
28 !Loader::includeModule('forum')
29 || !in_array($entityType, [ SONET_ENTITY_GROUP, SONET_ENTITY_USER ], true)
30 )
31 {
32 return $result;
33 }
34
35 $result = Permission::ACCESS_DENIED;
36
37 if (\CSocNetFeaturesPerms::canPerformOperation($currentUserId, $entityType, $entityId, 'forum', 'full', $isCurrentUserAdmin))
38 {
39 $result = Permission::FULL_ACCESS;
40 }
41 elseif (\CSocNetFeaturesPerms::CanPerformOperation($currentUserId, $entityType, $entityId, 'forum', 'newtopic', $isCurrentUserAdmin))
42 {
43 $result = Permission::CAN_ADD_TOPIC;
44 }
45 elseif (\CSocNetFeaturesPerms::CanPerformOperation($currentUserId, $entityType, $entityId, 'forum', 'answer', $isCurrentUserAdmin))
46 {
47 $result = Permission::CAN_ADD_MESSAGE;
48 }
49 elseif (\CSocNetFeaturesPerms::CanPerformOperation($currentUserId, $entityType, $entityId, 'forum', 'view', $isCurrentUserAdmin))
50 {
51 $result = Permission::CAN_READ;
52 }
53
54 return $result;
55 }
56}