- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_group.php
- Класс: CAllSocNetUserToGroup
- Вызов: CAllSocNetUserToGroup::UnBanMember
static function UnBanMember($userID, $groupId, $relationIdList, $currentUserIsAdmin): bool
{
global $APPLICATION;
$userID = (int)$userID;
if ($userID <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_USERID"), "ERROR_USERID");
return false;
}
$groupId = (int)$groupId;
if ($groupId <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_UR_EMPTY_GROUPID"), "ERROR_GROUPID");
return false;
}
if (!is_array($relationIdList))
{
return true;
}
$arGroup = CSocNetGroup::GetByID($groupId);
if (!$arGroup || !is_array($arGroup))
{
$APPLICATION->ThrowException(GetMessage("SONET_UG_ERROR_NO_GROUP_ID"), "ERROR_NO_GROUP");
return false;
}
$arUserPerms = CSocNetUserToGroup::InitUserPerms($userID, $arGroup, $currentUserIsAdmin);
if (!$arUserPerms["UserCanModifyGroup"] && !$arUserPerms["UserCanModerateGroup"])
{
$APPLICATION->ThrowException(GetMessage("SONET_UG_ERROR_NO_PERMS"), "ERROR_NO_PERMS");
return false;
}
$bSuccess = true;
foreach ($relationIdList as $relationId)
{
$relationId = (int)$relationId;
if ($relationId <= 0)
{
continue;
}
$arRelation = CSocNetUserToGroup::GetByID($relationId);
if (!$arRelation)
{
continue;
}
if (
(int)$arRelation["GROUP_ID"] !== $groupId
|| $arRelation["ROLE"] !== UserToGroupTable::ROLE_BAN
)
{
continue;
}
$arFields = array(
"ROLE" => UserToGroupTable::ROLE_USER,
"=DATE_UPDATE" => CDatabase::CurrentTimeFunction(),
);
if (CSocNetUserToGroup::Update($arRelation["ID"], $arFields))
{
CSocNetMessages::Add(array(
"FROM_USER_ID" => $userID,
"TO_USER_ID" => $arRelation["USER_ID"],
"MESSAGE" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_UNBANMEMBER_MESSAGE")),
"=DATE_CREATE" => CDatabase::CurrentTimeFunction(),
"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM
));
UserToGroup::addInfoToChat(array(
'group_id' => $groupId,
'user_id' => $userID,
'action' => UserToGroup::CHAT_ACTION_IN,
'role' => $arFields['ROLE']
));
}
else
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
{
$errorMessage = $e->GetString();
}
if ($errorMessage === '')
{
$errorMessage = Loc::getMessage('SONET_UR_ERROR_CREATE_USER2GROUP');
}
$APPLICATION->ThrowException($errorMessage, "ERROR_UNBANMEMBER");
$bSuccess = false;
}
}
return $bSuccess;
}