- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_group.php
- Класс: CAllSocNetUserToGroup
- Вызов: CAllSocNetUserToGroup::Delete
static function Delete($id, $sendExclude = false)
{
global $APPLICATION, $DB, $USER, $CACHE_MANAGER;
if (!CSocNetGroup::__ValidateID($id))
{
return false;
}
$id = (int)$id;
$relationFields = CSocNetUserToGroup::GetByID($id);
if (!$relationFields)
{
$APPLICATION->ThrowException(Loc::getMessage('SONET_NO_USER2GROUP'), 'ERROR_NO_USER2GROUP');
return false;
}
$res = GetModuleEvents("socialnetwork", "OnBeforeSocNetUserToGroupDelete");
while ($eventFields = $res->Fetch())
{
if (ExecuteModuleEventEx($eventFields, array($id)) === false)
{
return false;
}
}
$events = GetModuleEvents("socialnetwork", "OnSocNetUserToGroupDelete");
while ($eventFields = $events->Fetch())
{
ExecuteModuleEventEx($eventFields, [ $id, $relationFields ]);
}
EventServiceService::addEvent(EventServiceEventDictionary::EVENT_WORKGROUP_USER_DELETE, [
'GROUP_ID' => $relationFields['GROUP_ID'],
'USER_ID' => $relationFields['USER_ID'],
]);
if (Loader::includeModule('im'))
{
CIMNotify::DeleteByTag("SOCNET|INVITE_GROUP|" . (int)$relationFields['USER_ID'] . "|" . (int)$id);
}
$bSuccess = $DB->Query("DELETE FROM b_sonet_user2group WHERE ID = ".$id."", true);
CSocNetGroup::SetStat($relationFields["GROUP_ID"]);
CSocNetSearch::OnUserRelationsChange($relationFields["USER_ID"]);
$roleCacheKey = $relationFields['USER_ID'] . '_' . $relationFields['GROUP_ID'];
if (isset(self::$roleCache[$roleCacheKey]))
{
unset(self::$roleCache[$roleCacheKey]);
}
if ($bSuccess && defined("BX_COMP_MANAGED_CACHE"))
{
$CACHE_MANAGER->ClearByTag("sonet_user2group_G".$relationFields["GROUP_ID"]);
$CACHE_MANAGER->ClearByTag("sonet_user2group_U".$relationFields["USER_ID"]);
$CACHE_MANAGER->ClearByTag("sonet_user2group");
}
if (
$bSuccess
&& in_array($relationFields['ROLE'], [
UserToGroupTable::ROLE_MODERATOR,
UserToGroupTable::ROLE_USER,
], true)
)
{
$chatNotificationResult = false;
if (Loader::includeModule('im'))
{
$chatNotificationResult = UserToGroup::addInfoToChat([
'group_id' => $relationFields["GROUP_ID"],
'user_id' => $relationFields["USER_ID"],
'action' => UserToGroup::CHAT_ACTION_OUT,
'sendMessage' => $sendExclude,
]);
if ($sendExclude)
{
$arMessageFields = [
"TO_USER_ID" => $relationFields["USER_ID"],
"FROM_USER_ID" => 0,
"NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
"NOTIFY_MODULE" => "socialnetwork",
"NOTIFY_EVENT" => "invite_group",
"NOTIFY_TAG" => "SOCNET|INVITE_GROUP|" . (int)$relationFields["USER_ID"] . "|" . (int)$relationFields["ID"],
"NOTIFY_MESSAGE" => str_replace(
"#NAME#",
$relationFields["GROUP_NAME"],
Loc::getMessage('SONET_UG_EXCLUDE_MESSAGE')
),
];
CIMNotify::Add($arMessageFields);
}
}
if (
$sendExclude
&& !$chatNotificationResult
)
{
CSocNetUserToGroup::notifyImToModerators([
"TYPE" => "exclude",
"RELATION_ID" => $relationFields["ID"],
"USER_ID" => $relationFields["USER_ID"],
"GROUP_ID" => $relationFields["GROUP_ID"],
"GROUP_NAME" => $relationFields["GROUP_NAME"],
"EXCLUDE_USERS" => array($USER->getId()),
]);
}
}
CounterCounterService::addEvent(CounterEventEventDictionary::EVENT_WORKGROUP_USER_DELETE, [
'GROUP_ID' => (int)$relationFields['GROUP_ID'],
'USER_ID' => (int)$relationFields['USER_ID'],
'ROLE' => $relationFields['ROLE'],
'INITIATED_BY_TYPE' => ($relationFields['INITIATED_BY_TYPE']),
'RELATION_ID' => (int)$relationFields['ID'],
]);
return $bSuccess;
}