• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/helper/workgroup.php
  • Класс: BitrixSocialnetworkHelperWorkgroup
  • Вызов: Workgroup::acceptIncomingRequest
static function acceptIncomingRequest(array $fields = []): bool
{
	global $APPLICATION;

	$groupId = (int)($fields['groupId'] ?? 0);
	$userId = (int)($fields['userId'] ?? 0);

	if ($groupId <= 0)
	{
		throw new ArgumentException(Loc::getMessage('SOCIALNETWORK_HELPER_WORKGROUP_ERROR_WRONG_GROUP_ID'));
	}

	if ($userId <= 0)
	{
		throw new ArgumentException(Loc::getMessage('SOCIALNETWORK_HELPER_WORKGROUP_ERROR_WRONG_USER_ID'));
	}

	try
	{
		$relation = static::getRelation([
			'=GROUP_ID' => $groupId,
			'=USER_ID' => $userId,
		]);
	}
	catch (Exception $e)
	{
		throw new Exception($e->getMessage(), $e->getCode());
	}

	if (!HelperWorkgroupAccess::canProcessIncomingRequest([
		'userId' => $userId,
		'groupId' => $groupId,
	]))
	{
		throw new AccessDeniedException(Loc::getMessage('SOCIALNETWORK_HELPER_WORKGROUP_ERROR_OPERATION_NO_PERMS'));
	}

	if (!CSocNetUserToGroup::confirmRequestToBeMember(
		User::getCurrentUserId(),
		$groupId,
		[ $relation->getId() ]
	))
	{
		if ($ex = $APPLICATION->getException())
		{
			$errorMessage = $ex->getString();
		}
		else
		{
			$errorMessage = Loc::getMessage('SOCIALNETWORK_HELPER_WORKGROUP_ERROR_OPERATION_FAILED');
		}

		throw new Exception($errorMessage, 100);
	}

	return true;
}