• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/classes/general/event_calendar.php
  • Класс: CECCalendar
  • Вызов: CECCalendar::Edit
static function Edit($arParams, &$newSectionId, $bDisplay = true)
{
	global $DB;
	$iblockId = $arParams['iblockId'];
	$ownerId = $arParams['ownerId'];
	$ownerType = $arParams['ownerType'];
	$sectionId = $arParams['sectionId'];
	$arFields = $arParams['arFields'];

	if ($sectionId === 'none')
	{
		$sectionId = CEventCalendar::CreateSectionForOwner($ownerId, $ownerType, $iblockId); // Creating section for owner
		if ($sectionId === false)
			return false;

		if ($bDisplay)
		{
			?>StartTransaction();
	$bs = new CIBlockSection;

	if ($ownerType != 'USER' && $ownerType != 'GROUP')
		$ownerType = '';
	$key_color = "UF_".$ownerType."_CAL_COL";
	$key_export = "UF_".$ownerType."_CAL_EXP";
	$key_status = "UF_".$ownerType."_CAL_STATUS";

	$EXPORT = $arFields['EXPORT'] ? $arFields['EXPORT_SET'] : '';

	$arFields = Array(
		"ACTIVE"=>"Y",
		"IBLOCK_SECTION_ID"=>$sectionId,
		"IBLOCK_ID"=>$iblockId,
		"NAME"=>$arFields['NAME'],
		"DESCRIPTION"=>$arFields['DESCRIPTION'],
		$key_color => $arFields['COLOR'],
		$key_export => $EXPORT,
		$key_status => $arFields['PRIVATE_STATUS']
	);
	$GLOBALS[$key_color] = $COLOR;
	$GLOBALS[$key_export] = $EXPORT;
	$GLOBALS[$key_status] = $arFields['PRIVATE_STATUS'];
	$GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_".$iblockId."_SECTION", $arFields);

	if ($ownerType == 'GROUP' && $ownerId > 0)
		$arFields['SOCNET_GROUP_ID'] = $ownerId;

	if(isset($ID) && $ID > 0)
	{
		$res = $bs->Update($ID, $arFields);
	}
	else
	{
		$ID = $bs->Add($arFields);
		$res = ($ID > 0);
		if($res)
		{
			//This sets appropriate owner if section created by owner of the meeting and this calendar belongs to guest which is not current user
			if ($ownerType == 'USER' && $ownerId > 0)
				$DB->Query("UPDATE b_iblock_section SET CREATED_BY = ".intval($ownerId)." WHERE ID = ".intval($ID));
		}
	}
	if(!$res)
	{
		$DB->Rollback();
		return false;
	}

	$DB->Commit();
	return $ID;
}