- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/lib/Configuration/Configuration.php
- Класс: BitrixImConfigurationConfiguration
- Вызов: Configuration::replaceGroupForUser
static function replaceGroupForUser(int $userId, int $groupId, string $groupType): void
{
$query =
OptionGroupTable::query()
->addSelect('ID')
->registerRuntimeField(
'OPTION_ACCESS',
new Reference(
'OPTION_ACCESS',
OptionAccessTable::class,
Join::on('this.ID', 'ref.GROUP_ID'),
['join_type' => Join::TYPE_INNER]
)
)
->registerRuntimeField(
'USER_ACCESS',
new Reference(
'USER_ACCESS',
UserAccessTable::class,
Join::on('this.OPTION_ACCESS.ACCESS_CODE', 'ref.ACCESS_CODE'),
['join_type' => Join::TYPE_INNER]
)
)
->registerRuntimeField(
'OPTION_USER',
new Reference(
'OPTION_USER',
OptionUserTable::class,
Join::on('this.USER_ACCESS.USER_ID', 'ref.USER_ID'),
['join_type' => Join::TYPE_INNER]
)
)
->registerRuntimeField(
'OPTION_STATE',
new Reference(
'OPTION_STATE',
OptionStateTable::class,
Join::on('this.ID', 'ref.GROUP_ID'),
['join_type' => Join::TYPE_INNER]
)
)
->where('OPTION_USER.USER_ID', $userId)
->where('ID', '!=', $groupId)
->where(Query::expr()->count('OPTION_STATE.NAME'), '>', 0)
->setOrder(['SORT' => 'DESC', 'ID' => 'DESC'])
->setLimit(1)
;
$replacedGroup = $query->fetch()['ID'];
if ($groupType === self::NOTIFY_GROUP)
{
OptionUserTable::update($userId, ['NOTIFY_GROUP_ID' => $replacedGroup]);
}
elseif ($groupType === self::GENERAL_GROUP)
{
OptionUserTable::update($userId, ['GENERAL_GROUP_ID' => $replacedGroup]);
}
}