• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_restservice.php
  • Класс: CCalendarRestService
  • Вызов: CCalendarRestService::SectionUpdate
static function SectionUpdate($params = [], $nav = null, $server = null)
{
	$userId = CCalendar::GetCurUserId();
	$methodName = "calendar.section.update";

	if (isset($params['type']))
	{
		$type = $params['type'];
	}
	else
	{
		throw new RestException(Loc::getMessage('CAL_REST_PARAM_EXCEPTION', [
			'#REST_METHOD#' => $methodName,
			'#PARAM_NAME#' => 'type'
		]));
	}

	if (isset($params['ownerId']))
	{
		$ownerId = (int)$params['ownerId'];
	}
	elseif ($type === 'user')
	{
		$ownerId = $userId;
	}
	else
	{
		throw new RestException(Loc::getMessage('CAL_REST_PARAM_EXCEPTION', array('#REST_METHOD#' => $methodName, '#PARAM_NAME#' => 'ownerId')));

	}

	if (isset($params['id']) && (int)$params['id'] > 0)
	{
		$id = (int)$params['id'];
	}
	else
	{
		throw new RestException(Loc::getMessage('CAL_REST_SECT_ID_EXCEPTION'));
	}

	if (isset($params['name']) && !is_string($params['name']))
	{
		throw new RestException(Loc::getMessage('CAL_REST_PARAM_ERROR',
			[
				'#PARAM_NAME#' => 'name',
			]
		));
	}

	if (isset($params['description']) && !is_string($params['description']))
	{
		throw new RestException(Loc::getMessage('CAL_REST_PARAM_ERROR',
			[
				'#PARAM_NAME#' => 'description',
			]
		));
	}

	$accessController = new SectionAccessController($userId);
	$sectionModel =
		SectionModel::createFromId($id)
			->setType($type)
			->setOwnerId($ownerId)
	;
	if (!$accessController->check(ActionDictionary::ACTION_SECTION_EDIT, $sectionModel))
	{
		throw new RestException(Loc::getMessage('CAL_REST_ACCESS_DENIED'));
	}

	$arFields = [
		'ID' => $id,
		'CAL_TYPE' => $type,
		'OWNER_ID' => $ownerId
	];

	if (isset($params['name']) && trim($params['name']) !== '')
	{
		$arFields['NAME'] = trim($params['name']);
	}

	if (isset($params['description']) && trim($params['description']) !== '')
	{
		$arFields['DESCRIPTION'] = trim($params['description']);
	}

	if (isset($params['color']))
	{
		$arFields['COLOR'] = CCalendar::Color($params['color']);
	}

	if (isset($params['text_color']))
	{
		$arFields['TEXT_COLOR'] = CCalendar::Color($params['text_color']);
	}

	if (isset($params['access']) && is_array($params['access']))
	{
		$arFields['ACCESS'] = $params['access'];
	}

	$id = (int)CCalendar::SaveSection([
		'bAffectToDav' => false,
		'arFields' => $arFields
	]);

	if (!$id)
	{
		throw new RestException(Loc::getMessage('CAL_REST_SECTION_SAVE_ERROR'));
	}

	return $id;
}