15 public static function getGroup($params, $userId =
null)
17 if (!self::checkModules())
20 $params = is_array($params)? $params: [];
22 $userId = \Bitrix\Im\Common::getUserId($userId);
28 $cacheId =
'im_sonet_extranet_v3_'.$userId;
29 $cachePath =
'/bx/imc/sonet/extranet'.\Bitrix\Im\Common::getCacheUserPostfix($userId);
31 $cache = \Bitrix\Main\Application::getInstance()->getCache();
32 $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache();
34 if($cache->initCache(self::CACHE_TOKEN_TTL, $cacheId, $cachePath))
36 return $cache->getVars();
39 $cache->startDataCache();
41 $taggedCache->startTagCache($cachePath);
43 $db = \CSocNetUserToGroup::GetList(
47 "<=ROLE" => SONET_ROLES_USER,
48 "GROUP_SITE_ID" => \CExtranet::GetExtranetSiteID(),
49 "GROUP_ACTIVE" =>
"Y",
54 array(
"ID",
"GROUP_ID",
"GROUP_NAME")
59 while ($row = $db->GetNext(
true,
false))
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'])),
68 $taggedCache->registerTag(
'sonet_group_'.$row[
'GROUP_ID']);
69 $taggedCache->registerTag(
'sonet_user2group_G'.$row[
'GROUP_ID']);
72 if (count($groups) <= 0)
77 $taggedCache->registerTag(
'sonet_user2group');
79 $taggedCache->endTagCache();
81 $db = \CSocNetUserToGroup::GetList(
84 "@GROUP_ID" => $groupIds,
85 "<=ROLE" => SONET_ROLES_USER,
87 "USER_CONFIRM_CODE" =>
false
91 array(
"ID",
"USER_ID",
"GROUP_ID")
93 while ($row = $db->GetNext(
true,
false))
95 if($row[
"USER_ID"] == $userId || !isset($groups[
'SG'.$row[
'GROUP_ID']]))
98 $groups[
'SG'.$row[
'GROUP_ID']][
'USERS'][] = $row[
"USER_ID"];
101 $cache->endDataCache($groups);
108 $currentUserId = \Bitrix\Im\Common::getUserId($currentUserId);
109 if ($currentUserId <= 0)
114 if ($userId == $currentUserId)
121 if (is_array($groups))
123 foreach ($groups as $group)
125 foreach ($group[
'USERS'] as $uid)
127 $extranetUsers[$uid] = $uid;
132 return isset($extranetUsers[$userId]);
137 $currentUserId = \Bitrix\Im\Common::getUserId($currentUserId);
138 if ($currentUserId <= 0)
143 if (empty($userList))
150 if (is_array($groups))
152 foreach ($groups as $group)
154 foreach ($group[
'USERS'] as $uid)
156 $extranetUsers[$uid] = $uid;
161 return array_filter($userList,
function($userId) use ($extranetUsers) {
162 return isset($extranetUsers[$userId]);