1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
extranet.php
См. документацию.
1<?php
3
5
7{
8 const CACHE_TOKEN_TTL = 2592000; // 1 month
9
10 public static function checkModules()
11 {
12 return \Bitrix\Main\Loader::includeModule('extranet') && \Bitrix\Main\Loader::includeModule("socialnetwork");
13 }
14
15 public static function getGroup($params, $userId = null, bool $filterActiveUser = true)
16 {
17 if (!self::checkModules())
18 return false;
19
20 $params = is_array($params)? $params: [];
21
23 if ($userId <= 0)
24 {
25 return false;
26 }
27
28 $cacheId = 'im_sonet_extranet_v3_'.$userId;
29 $cachePath = '/bx/imc/sonet/extranet'.\Bitrix\Im\Common::getCacheUserPostfix($userId);
30
31 $cache = \Bitrix\Main\Application::getInstance()->getCache();
32 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
33
34 if($cache->initCache(self::CACHE_TOKEN_TTL, $cacheId, $cachePath))
35 {
36 return $cache->getVars();
37 }
38
39 $cache->startDataCache();
40
41 $taggedCache->startTagCache($cachePath);
42
43 $db = \CSocNetUserToGroup::GetList(
44 array(),
45 array(
46 "USER_ID" => $userId,
47 "<=ROLE" => SONET_ROLES_USER,
48 "GROUP_SITE_ID" => \CExtranet::GetExtranetSiteID(),
49 "GROUP_ACTIVE" => "Y",
50 "GROUP_CLOSED" => "N"
51 ),
52 false,
53 false,
54 array("ID", "GROUP_ID", "GROUP_NAME")
55 );
56
57 $groups = [];
58 $groupIds = [];
59 while ($row = $db->GetNext(true, false))
60 {
61 $groupIds[] = $row["GROUP_ID"];
62 $groups['SG'.$row['GROUP_ID']] = array(
63 'ID' => 'SG'.$row['GROUP_ID'],
64 'NAME' => Loc::getMessage('IM_INT_SN_GROUP_EXTRANET', Array('#GROUP_NAME#' => $row['GROUP_NAME'])),
65 'USERS' => []
66 );
67
68 $taggedCache->registerTag('sonet_group_'.$row['GROUP_ID']);
69 $taggedCache->registerTag('sonet_user2group_G'.$row['GROUP_ID']);
70 }
71
72 if (count($groups) <= 0)
73 {
74 return false;
75 }
76
77 $taggedCache->registerTag('sonet_user2group');
78
79 $taggedCache->endTagCache();
80
81 $filter = [
82 '@GROUP_ID' => $groupIds,
83 '<=ROLE' => SONET_ROLES_USER,
84 'USER_CONFIRM_CODE' => false
85 ];
86
87 if ($filterActiveUser)
88 {
89 $filter['USER_ACTIVE'] = 'Y';
90 }
91
92 $db = \CSocNetUserToGroup::GetList(
93 [],
94 $filter,
95 false,
96 false,
97 ['ID', 'USER_ID', 'GROUP_ID']
98 );
99 while ($row = $db->GetNext(true, false))
100 {
101 if($row['USER_ID'] == $userId || !isset($groups['SG'.$row['GROUP_ID']]))
102 continue;
103
104 $groups['SG'.$row['GROUP_ID']]['USERS'][] = $row['USER_ID'];
105 }
106
107 $cache->endDataCache($groups);
108
109 return $groups;
110 }
111
112 public static function isUserInGroup($userId, $currentUserId = null, bool $filterActiveUser = true)
113 {
114 $currentUserId = \Bitrix\Im\Common::getUserId($currentUserId);
115 if ($currentUserId <= 0)
116 {
117 return false;
118 }
119
120 if ($userId == $currentUserId)
121 {
122 return true;
123 }
124
125 $extranetUsers = [];
126 $groups = self::getGroup([], $currentUserId, $filterActiveUser);
127 if (is_array($groups))
128 {
129 foreach ($groups as $group)
130 {
131 foreach ($group['USERS'] as $uid)
132 {
133 $extranetUsers[$uid] = $uid;
134 }
135 }
136 }
137
138 return isset($extranetUsers[$userId]);
139 }
140
141 public static function filterUserList(array $userList, $currentUserId = null)
142 {
143 $currentUserId = \Bitrix\Im\Common::getUserId($currentUserId);
144 if ($currentUserId <= 0)
145 {
146 return false;
147 }
148
149 if (empty($userList))
150 {
151 return [];
152 }
153
154 $extranetUsers = [$currentUserId => $currentUserId];
155 $groups = self::getGroup([], $currentUserId);
156 if (is_array($groups))
157 {
158 foreach ($groups as $group)
159 {
160 foreach ($group['USERS'] as $uid)
161 {
162 $extranetUsers[$uid] = $uid;
163 }
164 }
165 }
166
167 return array_filter($userList, function($userId) use ($extranetUsers) {
168 return isset($extranetUsers[$userId]);
169 });
170 }
171}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getUserId($userId=null)
Определения common.php:73
static getGroup($params, $userId=null, bool $filterActiveUser=true)
Определения extranet.php:15
static filterUserList(array $userList, $currentUserId=null)
Определения extranet.php:141
static isUserInGroup($userId, $currentUserId=null, bool $filterActiveUser=true)
Определения extranet.php:112
static getInstance()
Определения application.php:98
static includeModule($moduleName)
Определения loader.php:67
$userList
Определения discount_coupon_list.php:276
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$uid
Определения hot_keys_act.php:8
$filter
Определения iblock_catalog_list.php:54
$groups
Определения options.php:30
return false
Определения prolog_main_admin.php:185
</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
const SONET_ROLES_USER
Определения include.php:31