• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/classes/general/event_calendar.php
  • Класс: CEventCalendar
  • Вызов: CEventCalendar::ModifyEvent
static function ModifyEvent($calendarId, $arFields)
{
	[$iblockId, $sectionId, $subSectionId, $ownerType, $ownerId] = $calendarId;
	$ownerType = mb_strtoupper($ownerType);

	$cal = self::GetInstance();

	$arFields["ACTIVE"] = "Y";
	$arFields["IBLOCK_SECTION"] = ($subSectionId > 0 ? $subSectionId : $sectionId);
	$arFields["IBLOCK_ID"] = $iblockId;

	if ($arFields["NAME"] == '')
		$arFields["NAME"] = GetMessage('EC_NONAME_EVENT');

	$eventId = ((isset($arFields["ID"]) && (intval($arFields["ID"]) > 0)) ? intval($arFields["ID"]) : 0);
	unset($arFields["ID"]);

	if($ownerType == 'USER' && $ownerId > 0)
		$arFields['CREATED_BY'] = $ownerId;

	$arFieldsNew = array();
	$arPropertiesNew = array();
	$len = mb_strlen("PROPERTY_");
	foreach ($arFields as $key => $value)
	{
		if (mb_substr($key, 0, $len) == "PROPERTY_")
			$arPropertiesNew[mb_substr($key, $len)] = $value;
		else
			$arFieldsNew[$key] = $value;
	}

	$accessibility = CECEvent::GetAccessibility($iblockId, $eventId);
	if ($accessibility == 'absent' && $accessibility == 'quest' && $arPropertiesNew['ACCESSIBILITY'] != $accessibility)
		$arPropertiesNew['ACCESSIBILITY'] = $accessibility;

	if (count($arPropertiesNew) > 0)
		$arFieldsNew["PROPERTY_VALUES"] = $arPropertiesNew;

	$bs = new CIBlockElement;
	$res = false;

	if ($eventId > 0)
	{
		$res = $bs->Update($eventId, $arFieldsNew, false);
	}
	else
	{
		$eventId = $bs->Add($arFieldsNew, false);
		$eventId = intval($eventId);
		$res = ($eventId > 0);
	}

	$cal->ClearCache('event_calendar/events/'.$iblockId.'/');
	return $res ? $eventId : $bs->LAST_ERROR;
}