• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/classes/general/event_calendar.php
  • Класс: CEventCalendar
  • Вызов: CEventCalendar::SyncCalendarItems
static function SyncCalendarItems($connectionType, $calendarId, $arCalendarItems)
{
	// $arCalendarItems:
	//Array(
	//	[0] => Array(
	//		[XML_ID] => AAATAGFudGlfYn...
	//		[MODIFICATION_LABEL] => DwAAABYAAA...
	//	)
	//	[1] => Array(
	//		[XML_ID] => AAATAGFudGlfYnVn...
	//		[MODIFICATION_LABEL] => DwAAABYAAAAQ...
	//	)
	//)

	[$iblockId, $sectionId, $subSectionId, $entityType, $entityId] = $calendarId;
	$entityType = mb_strtoupper($entityType);

	if ($connectionType == 'exchange')
		$xmlIdField = "BXDAVEX_LABEL";
	elseif ($connectionType == 'caldav')
		$xmlIdField = "BXDAVCD_LABEL";
	else
		return array();

	$arCalendarItemsMap = array();
	foreach ($arCalendarItems as $value)
		$arCalendarItemsMap[$value["XML_ID"]] = $value["MODIFICATION_LABEL"];

	$arModified = array();

	$arSelect = array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "XML_ID", "PROPERTY_".$xmlIdField);
	$arFilter = array(
		"IBLOCK_ID" => $iblockId,
		"ACTIVE" => "Y",
		"CHECK_PERMISSIONS" => "N",
		"INCLUDE_SUBSECTIONS" => "Y",
		"SECTION_ID" => ($subSectionId > 0 ? $subSectionId : $sectionId)
	);
	$dbEvents = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect);
	while ($arEvent = $dbEvents->Fetch())
	{
		if (array_key_exists($arEvent["XML_ID"], $arCalendarItemsMap))
		{
			if ($arEvent["PROPERTY_".$xmlIdField."_VALUE"] != $arCalendarItemsMap[$arEvent["XML_ID"]])
				$arModified[$arEvent["XML_ID"]] = $arEvent["ID"];

			unset($arCalendarItemsMap[$arEvent["XML_ID"]]);
		}
		else
		{
			self::DeleteCalendarEvent($calendarId, $arEvent["ID"], $userId);
		}
	}

	$arResult = array();
	foreach ($arCalendarItems as $value)
	{
		if (array_key_exists($value["XML_ID"], $arModified))
		{
			$arResult[] = array(
				"XML_ID" => $value["XML_ID"],
				"ID" => $arModified[$value["XML_ID"]]
			);
		}
	}

	foreach ($arCalendarItemsMap as $key => $value)
	{
		$arResult[] = array(
			"XML_ID" => $key,
			"ID" => 0
		);
	}

	return $arResult;
}