• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/classes/general/event_calendar.php
  • Класс: CEventCalendar
  • Вызов: CEventCalendar::CreateSectionForOwner
static function CreateSectionForOwner($ownerId, $ownerType, $iblockId)
{
	global $DB;
	$bs = new CIBlockSection;

	if ($ownerType == 'USER')
	{
		$r = CUser::GetByID($ownerId);
		if($arUser = $r->Fetch())
		{
			$name = $arUser['NAME'].' '.$arUser['LAST_NAME'];
			if (mb_strlen($name) < 2)
				$name = GetMessage('EC_DEF_SECT_USER').$arUser['ID'];
		}
		else
			return false;
	}
	elseif ($ownerType == 'GROUP')
	{
		if (!class_exists('CSocNetGroup'))
			return false;
		$arGroup = CSocNetGroup::GetByID($ownerId);
		if($arGroup && is_array($arGroup))
			$name = GetMessage('EC_DEF_SECT_GROUP').$arGroup['NAME'];
		else
			return false;
	}
	else
		return false;

	$arFields = Array(
		"ACTIVE" => "Y",
		"IBLOCK_SECTION_ID" => 0,
		"IBLOCK_ID" => $iblockId,
		"NAME" => $name,
	);

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

	$DB->StartTransaction();

	$ID = $bs->Add($arFields);
	$res = ($ID > 0);

	if(!$res)
	{
		$DB->Rollback();
		$strWarning = $bs->LAST_ERROR;
		return false;
	}
	else
	{
		//This sets appropriate owner if section created by owner of the meeting and this calendar belongs to guest which is not current user
		if($arUser)
			$DB->Query("UPDATE b_iblock_section SET CREATED_BY = ".intval($arUser["ID"])." WHERE ID = ".intval($ID));

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