24 $APPLICATION->ThrowException(
"System error 870164",
"ERROR");
45 $groupFeatureType =
"";
59 $arGroupFeature = CSocNetFeatures::GetByID(
$arFields[
"FEATURE_ID"]);
60 if ($arGroupFeature !=
false)
62 $groupFeature = $arGroupFeature[
"FEATURE"];
63 $groupFeatureType = $arGroupFeature[
"ENTITY_TYPE"];
68 $dbGroupFeature = CSocNetFeaturesPerms::GetList(
73 array(
"FEATURE_FEATURE",
"FEATURE_ENTITY_TYPE")
75 if ($arGroupFeature = $dbGroupFeature->Fetch())
77 $groupFeature = $arGroupFeature[
"FEATURE_FEATURE"];
78 $groupFeatureType = $arGroupFeature[
"FEATURE_ENTITY_TYPE"];
105 if ($groupFeatureType ==
'')
109 $arGroupFeature = CSocNetFeatures::GetByID(
$arFields[
"FEATURE_ID"]);
110 if ($arGroupFeature !=
false)
112 $groupFeatureType = $arGroupFeature[
"ENTITY_TYPE"];
117 $dbGroupFeature = CSocNetFeaturesPerms::GetList(
122 array(
"FEATURE_FEATURE",
"FEATURE_ENTITY_TYPE")
124 if ($arGroupFeature = $dbGroupFeature->Fetch())
126 $groupFeatureType = $arGroupFeature[
"FEATURE_ENTITY_TYPE"];
433 $userID = (int)$userID;
435 if ((is_array($id) &&
count($id) <= 0) || (!is_array($id) && $id <= 0))
452 $bWorkWithClosedGroups = (COption::GetOptionString(
"socialnetwork",
"work_with_closed_groups",
"N") ===
"Y");
455 $arGroupToGet =
array();
456 foreach($id as $group_id)
458 if ($featureOperationPerms[$group_id] ==
false)
460 $arReturn[$group_id] =
false;
464 $arGroupToGet[] = $group_id;
468 $arGroupToGet = array_unique($arGroupToGet);
470 $userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $arGroupToGet);
471 $arGroupToGet =
array();
472 if (is_array($userRoleInGroup))
474 foreach($userRoleInGroup as $group_id => $role)
478 $arReturn[$group_id] =
false;
482 $arGroupToGet[] = $group_id;
487 $arGroupToGet = array_unique($arGroupToGet);
490 (is_array($arGroupToGet) &&
count($arGroupToGet) <= 0)
491 || (!is_array($arGroupToGet) && intval($arGroupToGet) <= 0)
495 foreach($id as $group_id)
497 $arReturn[$group_id] =
false;
502 $resGroupTmp = CSocNetGroup::GetList(
503 array(
"ID" =>
"ASC"),
504 array(
"@ID" => $arGroupToGet),
507 array(
'ID',
'VISIBLE',
'CLOSED')
509 while ($arGroupTmp = $resGroupTmp->Fetch())
512 $arGroupTmp[
"CLOSED"] ===
"Y"
516 if (!$bWorkWithClosedGroups)
518 $arReturn[$arGroupTmp[
"ID"]] =
false;
525 if ($bCurrentUserIsAdmin)
527 $arReturn[$arGroupTmp[
"ID"]] =
true;
533 if ($arGroupTmp[
"VISIBLE"] ===
"N")
539 $arReturn[$arGroupTmp[
"ID"]] =
true;
546 $arReturn[$arGroupTmp[
'ID']] =
547 in_array($userRoleInGroup[$arGroupTmp[
"ID"]], UserToGroupTable::getRolesMember(),
true)
548 && User::isIntranet($userID);
557 $arReturn[$arGroupTmp[
"ID"]] =
true;
561 $arReturn[$arGroupTmp[
"ID"]] =
false;
565 if ($userRoleInGroup[$arGroupTmp[
"ID"]] ==
false)
567 $arReturn[$arGroupTmp[
"ID"]] =
false;
575 $arReturn[$arGroupTmp[
"ID"]] =
true;
579 $arReturn[$arGroupTmp[
"ID"]] =
false;
585 if (in_array($userRoleInGroup[$arGroupTmp[
"ID"]], UserToGroupTable::getRolesMember(),
true))
587 $arReturn[$arGroupTmp[
"ID"]] =
true;
591 $arReturn[$arGroupTmp[
"ID"]] =
false;
599 $arReturn[$arGroupTmp[
"ID"]] =
true;
603 $arReturn[$arGroupTmp[
"ID"]] =
false;
608 return $arReturn ??
false;
614 if ($featureOperationPerms ==
false)
619 $userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $id);
625 $arGroupTmp = WorkgroupTable::getList([
626 'select' => [
'CLOSED',
'VISIBLE'],
627 'filter' => [
'ID' => $id],
631 ($arGroupTmp[
"CLOSED"] ??
null) ===
"Y"
635 if (!$bWorkWithClosedGroups)
643 if ($bCurrentUserIsAdmin)
650 if ($arGroupTmp[
"VISIBLE"] ===
"N")
662 return ($userID > 0);
668 in_array($userRoleInGroup, UserToGroupTable::getRolesMember(),
true)
669 && User::isIntranet($userID);
672 if ($userRoleInGroup ==
false)
684 return (in_array($userRoleInGroup, UserToGroupTable::getRolesMember()));
697 foreach($id as $entity_id)
700 if ($featureOperationPerms[$entity_id] ==
false)
702 $arReturn[$entity_id] =
false;
710 $arReturn[$entity_id] =
true;
714 if ($bCurrentUserIsAdmin)
716 $arReturn[$entity_id] =
true;
720 if ($userID == $entity_id)
722 $arReturn[$entity_id] =
true;
730 $arReturn[$entity_id] =
false;
737 $arReturn[$entity_id] =
false;
743 $arReturn[$entity_id] =
true;
749 $arReturn[$entity_id] = ($userID > 0);
767 if ($featureOperationPerms ==
false)
777 if ($bCurrentUserIsAdmin)
800 return ($userID > 0);
819 static $arSonetGroupCache =
array();
833 foreach($id as $TmpGroupID)
835 $arReturn[$TmpGroupID] =
false;
844 $feature = mb_strtolower(trim($feature));
851 foreach($id as $TmpGroupID)
853 $arReturn[$TmpGroupID] =
false;
872 foreach($id as $TmpGroupID)
874 $arReturn[$TmpGroupID] =
false;
883 $operation = mb_strtolower(Trim($operation));
892 foreach($id as $TmpGroupID)
894 $arReturn[$TmpGroupID] =
false;
903 global $arSonetFeaturesPermsCache;
904 if (!isset($arSonetFeaturesPermsCache) || !is_array($arSonetFeaturesPermsCache))
906 $arSonetFeaturesPermsCache =
array();
911 $arFeaturesPerms =
array();
912 $arGroupToGet =
array();
913 foreach($id as $TmpGroupID)
915 $arFeaturesPerms[$TmpGroupID] =
array();
917 if (!array_key_exists(
$type.
"_".$TmpGroupID, $arSonetFeaturesPermsCache))
919 $arGroupToGet[] = $TmpGroupID;
923 $arFeaturesPerms[$TmpGroupID] = $arSonetFeaturesPermsCache[
$type.
"_".$TmpGroupID];
927 $arGroupToGet = array_unique($arGroupToGet);
929 if (!empty($arGroupToGet))
931 $rsSonetGroup = CSocNetGroup::GetList(
933 array(
'@ID' => $arGroupToGet),
936 array(
'ID',
'VISIBLE',
'OPENED')
938 while ($arSonetGroup = $rsSonetGroup->Fetch())
940 if (!isset($arSonetGroupCache[$arSonetGroup[
'ID']]))
942 $arSonetGroupCache[$arSonetGroup[
'ID']] =
array(
943 'VISIBLE' => $arSonetGroup[
'VISIBLE'],
944 'OPENED' => $arSonetGroup[
'OPENED']
949 $dbResult = CSocNetFeaturesPerms::GetList(
952 "@FEATURE_ENTITY_ID" => $arGroupToGet,
953 "FEATURE_ENTITY_TYPE" =>
$type,
954 "FEATURE_ACTIVE" =>
"Y"
958 array(
"OPERATION_ID",
"FEATURE_ENTITY_ID",
"FEATURE_FEATURE",
"ROLE")
963 !array_key_exists(
$arResult[
"FEATURE_ENTITY_ID"], $arFeaturesPerms)
964 || !array_key_exists(
$arResult[
"FEATURE_FEATURE"], $arFeaturesPerms[
$arResult[
"FEATURE_ENTITY_ID"]])
975 foreach ($id as $TmpEntityID)
977 $arSonetFeaturesPermsCache[
$type.
"_".$TmpEntityID] = $arFeaturesPerms[$TmpEntityID];
982 !array_key_exists($feature, $arFeaturesPerms[$TmpEntityID])
983 || !array_key_exists($operation, $arFeaturesPerms[$TmpEntityID][$feature])
989 isset($arSonetGroupCache[$TmpEntityID])
990 && $arSonetGroupCache[$TmpEntityID][
'OPENED'] ===
'Y'
991 && $arSonetGroupCache[$TmpEntityID][
'VISIBLE'] ===
'Y'
992 && $feature ===
"blog"
1011 $featureOperationPerms =
$perm;
1016 $featureOperationPerms = $arFeaturesPerms[$TmpEntityID][$feature][$operation];
1021 if (!array_key_exists($feature, $arFeaturesPerms[$TmpEntityID]))
1025 elseif (!array_key_exists($operation, $arFeaturesPerms[$TmpEntityID][$feature]))
1031 $featureOperationPerms = $arFeaturesPerms[$TmpEntityID][$feature][$operation];
1040 $arReturn[$TmpEntityID] = $featureOperationPerms;
1054 $arFeaturesPerms =
array();
1055 if (array_key_exists(
$type.
"_".$id, $arSonetFeaturesPermsCache))
1057 $arFeaturesPerms = $arSonetFeaturesPermsCache[
$type.
"_".$id];
1062 $cache_time = 31536000;
1063 $cache_id =
"entity_".
"_".
$type.
"_".$id;
1064 $cache_path = self::getCachePath(
$type, $id);
1068 if ($cache->InitCache($cache_time, $cache_id, $cache_path))
1070 $arCacheVars = $cache->GetVars();
1071 $arTmp = $arCacheVars[
"RESULT"];
1075 $cache->StartDataCache($cache_time, $cache_id, $cache_path);
1076 if (defined(
"BX_COMP_MANAGED_CACHE"))
1081 $dbResult = CSocNetFeaturesPerms::GetList(
1084 "FEATURE_ENTITY_ID" => $id,
1085 "FEATURE_ENTITY_TYPE" =>
$type,
1086 "FEATURE_ACTIVE" =>
"Y"
1090 array(
"ID",
"OPERATION_ID",
"FEATURE_ID",
"FEATURE_FEATURE",
"ROLE")
1094 if (defined(
"BX_COMP_MANAGED_CACHE"))
1101 if (defined(
"BX_COMP_MANAGED_CACHE"))
1105 Array(
"ENTITY_ID" => $id,
"ENTITY_TYPE" =>
$type),
1116 if (defined(
"BX_COMP_MANAGED_CACHE"))
1125 $CACHE_MANAGER->RegisterTag(
"USER_CARD_".intval($id / TAGGED_user_card_size));
1131 $arCacheData = Array(
1135 if(defined(
"BX_COMP_MANAGED_CACHE"))
1140 $cache->EndDataCache($arCacheData);
1145 if (!array_key_exists(
$arResult[
"FEATURE_FEATURE"], $arFeaturesPerms))
1151 $arSonetFeaturesPermsCache[
$type.
"_".$id] = $arFeaturesPerms;
1157 !array_key_exists($feature, $arFeaturesPerms)
1158 || !array_key_exists($operation, $arFeaturesPerms[$feature])
1161 if (!isset($arSonetGroupCache[$id]))
1163 $sonetGroup = WorkgroupTable::getList([
1164 'select' => [
'OPENED',
'VISIBLE'],
1165 'filter' => [
'ID' => $id],
1168 $arSonetGroupCache[$id] = [
1169 'OPENED' => $sonetGroup[
'OPENED'] ??
null,
1170 'VISIBLE' => $sonetGroup[
'VISIBLE'] ??
null,
1177 isset($arSonetGroupCache[$id])
1178 && $arSonetGroupCache[$id][
'OPENED'] ===
'Y'
1179 && $arSonetGroupCache[$id][
'VISIBLE'] ===
'Y'
1180 && $feature ===
"blog"
1199 $featureOperationPerms =
$perm;
1204 $featureOperationPerms = $arFeaturesPerms[$feature][$operation];
1209 if (!array_key_exists($feature, $arFeaturesPerms))
1213 elseif (!array_key_exists($operation, $arFeaturesPerms[$feature]))
1219 $featureOperationPerms = $arFeaturesPerms[$feature][$operation];
1228 return $featureOperationPerms;