- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/user_group.php
- Класс: CAllSocNetUserToGroup
- Вызов: CAllSocNetUserToGroup::TransferMember2Moderator
static function TransferMember2Moderator($userID, $groupId, $relationIdList): bool
{
global $APPLICATION, $USER;
$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;
}
$bSuccess = true;
$arSuccessRelations = array();
$relationsToUpdateCount = 0;
foreach ($relationIdList as $relationId)
{
$relationId = (int)$relationId;
if ($relationId <= 0)
{
continue;
}
$arRelation = CSocNetUserToGroup::GetByID($relationId);
if (
!$arRelation
|| (int)$arRelation["GROUP_ID"] !== $groupId
|| $arRelation["ROLE"] !== UserToGroupTable::ROLE_USER
)
{
continue;
}
$relationsToUpdateCount++;
$arFields = array(
"ROLE" => UserToGroupTable::ROLE_MODERATOR,
"=DATE_UPDATE" => CDatabase::CurrentTimeFunction(),
);
if (CSocNetUserToGroup::update($arRelation["ID"], $arFields))
{
$arSuccessRelations[] = $arRelation;
self::notifyModeratorAdded(array(
'userId' => $userID,
'groupId' => $groupId,
'relationFields' => $arRelation,
'groupFields' => $arGroup
));
}
else
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
{
$errorMessage = $e->GetString();
}
if ($errorMessage === '')
{
$errorMessage = Loc::getMessage('SONET_UR_ERROR_CREATE_USER2GROUP');
}
$APPLICATION->ThrowException($errorMessage, "ERROR_MEMBER2MOD");
$bSuccess = false;
}
}
if ($relationsToUpdateCount <= 0)
{
$APPLICATION->ThrowException(GetMessage("SONET_UR_ERROR_MEM2MOD_EMPTY_CORRECT_LIST"), "MOD2MEM_EMPTY_CORRECT_LIST");
return false;
}
$successfulUserIdList = array();
foreach ($arSuccessRelations as $arRel)
{
$arNotifyParams = array(
"TYPE" => "moderate",
"RELATION_ID" => $arRel["ID"],
"USER_ID" => $arRel["USER_ID"],
"GROUP_ID" => $arRel["GROUP_ID"],
"GROUP_NAME" => $arRel["GROUP_NAME"],
"EXCLUDE_USERS" => array($arRel["USER_ID"], $USER->GetID())
);
CSocNetUserToGroup::NotifyImToModerators($arNotifyParams);
CSocNetSubscription::Set($arRel["USER_ID"], "SG".$arRel["GROUP_ID"], "Y");
$successfulUserIdList[] = $arRel["USER_ID"];
}
$successfulUserIdList = array_unique($successfulUserIdList);
if (!empty($successfulUserIdList))
{
IntegrationImChatWorkgroup::setChatManagers(array(
'group_id' => $groupId,
'user_id' => $successfulUserIdList,
'set' => true
));
}
if (
$bSuccess
&& count($arSuccessRelations) <= 0
)
{
$errorMessage = "";
if ($e = $APPLICATION->GetException())
{
$errorMessage = $e->GetString();
}
if ($errorMessage === '')
{
$errorMessage = Loc::getMessage('SONET_UR_ERROR_MEM2MOD_INCORRECT_PARAMS');
}
$APPLICATION->ThrowException($errorMessage, "MEM2MOD_INCORRECT_PARAMS");
$bSuccess = false;
}
return $bSuccess;
}