• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/iblocksocnetbizproc.php
  • Класс: CIBlockDocumentWebdavSocnet
  • Вызов: CIBlockDocumentWebdavSocnet::GetUserGroups
static function GetUserGroups($documentType = null, $documentId = null, $userId = 0)
{
	$documentType = trim(is_array($documentType) ? $documentType[2] : $documentType);

	if (is_array($documentType))
		$documentType = null;
	else
		$documentType = (($documentType == null || $documentType == '') ? null : $documentType);

	$userId = intval($userId);
	$documentIdReal = $documentId = (is_array($documentId) ? $documentId[2] : $documentId);
	$documentId = intval($documentId);
	$arParameters = array();

	if (($documentType == null && $documentId <= 0) || $userId <= 0)
		return false;
	elseif ($documentType != null)
	{
		$res = explode("_", $documentType);
		if (count($res) != 4)
			return false;
		$arParameters = array(
			"IBlockId" => intval($res[1]),
			"OwnerType" => $res[2],
			"OwnerId" => intval($res[3]));
	}

	if ($documentId > 0)
	{
		$db_res = CIBlockElement::GetList(
			array(),
			array("ID" => $documentId, "SHOW_NEW"=>"Y", "SHOW_HISTORY" => "Y"),
			false,
			false,
			array("ID", "IBLOCK_ID", "CREATED_BY", "IBLOCK_SECTION_ID")
		);
		if ($db_res && $arElement = $db_res->Fetch())
		{
			$dbSectionsChain = CIBlockSection::GetNavChain($arElement["IBLOCK_ID"], $arElement["IBLOCK_SECTION_ID"]);
			if ($arSect = $dbSectionsChain->Fetch())
			{
				$arParameters["OwnerType"] = (intval($arSect["SOCNET_GROUP_ID"]) > 0 ? "group" : "user");
				$arParameters["OwnerId"] = (intval($arSect["SOCNET_GROUP_ID"]) > 0 ? $arSect["SOCNET_GROUP_ID"] : $arSect["CREATED_BY"]);

				$arParameters["IBlockId"] = $arElement["IBLOCK_ID"];
				$arParameters["CreatedBy"] = $arElement["CREATED_BY"];
			}
		}
	}

	$arParameters["UserGroups"] = array();

	if ($arParameters["OwnerType"] == "group")
	{
		$arParameters["UserGroups"][] = SONET_ROLES_ALL;
		$r = CSocNetUserToGroup::GetUserRole($userId, $arParameters["OwnerId"]);
		if ($r <> '')
		{
			$arParameters["UserGroups"][] = $r;
			foreach ($GLOBALS["arSocNetAllowedInitiatePerms"] as $perm)
				if ($r < $perm)
					$arParameters["UserGroups"][] = $perm;
		}
	}
	elseif ($arParameters["OwnerType"] == "user")
	{
		$arParameters["UserGroups"][] = SONET_RELATIONS_TYPE_ALL;
		if ($arParameters["OwnerId"] == $userId)
			$arParameters["UserGroups"][] = SONET_RELATIONS_TYPE_NONE;
		if (CSocNetUserRelations::IsFriends($userId, $arParameters["OwnerId"]))
			$arParameters["UserGroups"][] = SONET_RELATIONS_TYPE_FRIENDS;
	}
	if ($documentIdReal != null && ($documentId <= 0 || $userId > 0 && $userId == $arParameters["CreatedBy"]))
		$arParameters["UserGroups"][] = "author";
	return $arParameters["UserGroups"];
}