• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/icloud/apiservice.php
  • Класс: BitrixCalendarSyncIcloudApiService
  • Вызов: ApiService::prepareInstanceData
private function prepareInstanceData(
	Event $event,
	string $path,
	string $xmlId,
	?array $data,
	Date $excludeDate = null
): array
{
	$instancesOriginalDate = [];
	$exDates = $event->getExcludedDateCollection();
	$excludedInstance = $excludeDate ? $excludeDate->format('Ymd') : null;

	$instances = EventTable::query()
		->setSelect(['*'])
		->where('RECURRENCE_ID', $event->getParentId())
		->where('DELETED', 'N')
		->where('OWNER_ID', $event->getOwner()->getId())
		// ->whereNot('MEETING_STATUS', 'N')
		->where(Query::filter() // TODO: it's better to optimize it and don't use 'OR' logic here
			 ->logic('or')
			 ->whereNot('MEETING_STATUS', 'N')
			 ->whereNull('MEETING_STATUS')
		)
		->exec()->fetchCollection()
	;

	foreach ($instances as $instance)
	{
		$originalDate = $instance->getOriginalDateFrom()
			? $instance->getOriginalDateFrom()->format('Ymd')
			: $instance->getDateFrom()->format('Ymd')
		;
		if ($originalDate === $excludedInstance)
		{
			$instances->remove($instance);
			continue;
		}

		$instancesOriginalDate[] = $originalDate;
	}

	if ($exDates)
	{
		/**
		 * @var int $key
		 * @var Date $exDate
		 */
		foreach ($exDates->getCollection() as $key => $exDate)
		{
			if (in_array($exDate->format('Ymd'), $instancesOriginalDate, true))
			{
				$exDates->remove($key);
			}
		}
		$event->setExcludedDateCollection($exDates);
	}

	$eventPath = $this->davClient->GetRequestEventPath($path, $xmlId);
	$eventPath = $this->getPath($eventPath, $xmlId);
	$calendarData[] = EventBuilder::getInstance()->getContent($event, $data);

	foreach ($instances as $instance)
	{
		$instanceObject = (new EventBuilderFromEntityObject($instance))->build();
		$instanceObject->setUid($xmlId);
		$calendarData[] = EventBuilder::getInstance()->getContent($instanceObject, $data);
	}
	if ($calendarData)
	{
		$calendarData = (new RecurrenceEventBuilder($calendarData))->Render();
	}

	return [$eventPath, $calendarData];
}