- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_restservice.php
- Класс: CCalendarRestService
- Вызов: CCalendarRestService::SectionAdd
static function SectionAdd($params = [], $nav = null, $server = null)
{
$userId = CCalendar::GetCurUserId();
$methodName = "calendar.section.add";
$DEFAULT_COLOR = '#E6A469';
$DEFAULT_TEXT_COLOR = '#000000';
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', [
'#REST_METHOD#' => $methodName,
'#PARAM_NAME#' => 'ownerId'
]));
}
if (!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',
]
));
}
$perm = CCalendar::GetPermissions([
'type' => $type,
'ownerId' => $ownerId,
'userId' => $userId,
'setProperties' => false
]);
if (!$perm['section_edit'])
{
throw new RestException(Loc::getMessage('CAL_REST_ACCESS_DENIED'));
}
$arFields = [
'CAL_TYPE' => $type,
'OWNER_ID' => $ownerId,
'NAME' => (isset($params['name']) && trim($params['name']) != '') ? trim($params['name']) : '',
'DESCRIPTION' => (isset($params['description']) && trim($params['description']) != '') ? trim($params['description']) : ''
];
if (isset($params['export']['ALLOW'], $params['export']['SET']))
{
$arFields['EXPORT'] = array(
'ALLOW' => (bool)$params['export']['ALLOW'],
'SET' => $params['export']['SET']
);
}
if (isset($params['color']))
{
$arFields['COLOR'] = CCalendar::Color($params['color'], $DEFAULT_COLOR);
}
else
{
$arFields['COLOR'] = $DEFAULT_COLOR;
}
if (isset($params['text_color']))
{
$arFields['TEXT_COLOR'] = CCalendar::Color($params['text_color'], $DEFAULT_TEXT_COLOR);
}
else
{
$arFields['TEXT_COLOR'] = $DEFAULT_TEXT_COLOR;
}
if (isset($params['access']) && is_array($params['access']))
{
$arFields['ACCESS'] = $params['access'];
}
$id = CCalendar::SaveSection([
'bAffectToDav' => false,
'arFields' => $arFields
]);
if (!$id)
{
throw new RestException(Loc::getMessage('CAL_REST_SECTION_NEW_ERROR'));
}
CCalendarSect::SetClearOperationCache(true);
return $id;
}