• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::chatCalendarDelete
static function chatCalendarDelete($arParams, $n, CRestServer $server)
{
	$arParams = array_change_key_case($arParams, CASE_UPPER);

	if (!isset($arParams['LINK_ID']) || (int)$arParams['LINK_ID'] <= 0)
	{
		throw new BitrixRestRestException('LINK_ID can`t be empty', 'LINK_ID_EMPTY', CRestServer::STATUS_WRONG_REQUEST);
	}

	$linkId = (int)$arParams['LINK_ID'];
	$calendar = new BitrixImV2LinkCalendarCalendarItem($linkId);
	if ($calendar->getId() === null)
	{
		throw new BitrixRestRestException('Calendar event not found', BitrixImV2EntityCalendarCalendarError::NOT_FOUND, CRestServer::STATUS_NOT_FOUND);
	}

	$chatId = $calendar->getChatId();
	$chat = BitrixImV2Chat::getInstance($chatId);

	if (!$chat->hasAccess())
	{
		throw new BitrixRestRestException('You do not have access to this chat', BitrixImV2RestRestError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	global $USER;
	$userId = (int)$USER->GetID();

	if ($userId !== $calendar->getAuthorId() && !$USER->IsAdmin())
	{
		throw new BitrixRestRestException('You do not have access to delete this calendar event', BitrixImV2EntityCalendarCalendarError::ACCESS_ERROR, CRestServer::STATUS_FORBIDDEN);
	}

	$deleteResult = (new BitrixImV2LinkCalendarCalendarService())->unregisterCalendar($calendar);

	if (!$deleteResult->isSuccess())
	{
		throw new BitrixRestRestException('Failed to delete calendar event', BitrixImV2EntityCalendarCalendarError::DELETE_ERROR, CRestServer::STATUS_INTERNAL);
	}

	return true;
}