• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/classes/general/calendar_sync.php
  • Класс: CCalendarSync
  • Вызов: CCalendarSync::GetCaldavItemsInfo
static function GetCaldavItemsInfo($userId, $type, $calculateTimestamp): ?array
{
	$connections = [];
	$bCalDAV = CCalendar::IsCalDAVEnabled() && $type === 'user';
	$bGoogleApi = CCalendar::isGoogleApiEnabled() && $type === 'user';

	if ($bCalDAV || $bGoogleApi)
	{
		$res = CDavConnection::GetList(
			['ID' => 'DESC'],
			[
				'ENTITY_TYPE' => 'user',
				'ENTITY_ID' => $userId,
				'ACCOUNT_TYPE' =>
					[
						GoogleHelper::GOOGLE_ACCOUNT_TYPE_CALDAV,
						GoogleHelper::GOOGLE_ACCOUNT_TYPE_API,
						BitrixCalendarSyncCaldavHelper::CALDAV_TYPE,
						BitrixCalendarSyncIcloudHelper::ACCOUNT_TYPE,
						BitrixCalendarSyncOffice365Helper::ACCOUNT_TYPE
					],
				'IS_DELETED' => 'N'
			]
		);
		$isRussian = Util::checkRuZone();
		/** @var GoogleHelper $googleHelper */
		$googleHelper = ServiceLocator::getInstance()->get('calendar.service.google.helper');
		/** @var BitrixCalendarSyncCaldavHelper $caldavHelper */
		$caldavHelper = ServiceLocator::getInstance()->get('calendar.service.caldav.helper');
		/** @var BitrixCalendarSyncIcloudHelper $iCloudHelper */
		$iCloudHelper = ServiceLocator::getInstance()->get('calendar.service.icloud.helper');
		/** @var BitrixCalendarSyncOffice365Helper $office365Helper */
		$office365Helper = ServiceLocator::getInstance()->get('calendar.service.office365.helper');
		while ($connection = $res->Fetch())
		{
			if ($connection['ACCOUNT_TYPE'] === BitrixCalendarSyncCaldavHelper::CALDAV_TYPE)
			{
				if ($caldavHelper->isYandex($connection['SERVER_HOST']) && $isRussian)
				{
					$connections[BitrixCalendarSyncCaldavHelper::YANDEX_TYPE . $connection['ID']] = [
						'id' => $connection['ID'],
						'active' => true,
						'connected' => true,
						'userName' => $connection['SERVER_USERNAME'],
						'connectionName' => $connection['NAME'],
						'type' => BitrixCalendarSyncCaldavHelper::YANDEX_TYPE,
						'status' => self::isConnectionSuccess($connection['LAST_RESULT']),
						'server' => $connection['SERVER'],
						'syncOffset' => time() - $calculateTimestamp($connection['SYNCHRONIZED']),
					];
				}
				else
				{
					$connections[BitrixCalendarSyncCaldavHelper::CALDAV_TYPE . $connection['ID']] = [
						'id' => $connection['ID'],
						'active' => true,
						'connected' => true,
						'userName' => $connection['SERVER_USERNAME'],
						'connectionName' => $connection['NAME'],
						'type' => BitrixCalendarSyncCaldavHelper::CALDAV_TYPE,
						'status' => self::isConnectionSuccess($connection['LAST_RESULT']),
						'server' => $connection['SERVER'],
						'syncOffset' => time() - $calculateTimestamp($connection['SYNCHRONIZED']),
					];
				}
			}
			else if (
				$iCloudHelper->isVendorConnection($connection['ACCOUNT_TYPE'])
				|| $office365Helper->isVendorConnection($connection['ACCOUNT_TYPE'])
			)
			{
				$connections[$connection['ACCOUNT_TYPE']] = [
					'id' => $connection['ID'],
					'active' => true,
					'connected' => true,
					'userName' => $connection['SERVER_USERNAME'],
					'connectionName' => $connection['NAME'],
					'type' => $connection['ACCOUNT_TYPE'],
					'status' => self::isConnectionSuccess($connection['LAST_RESULT']),
					'server' => $connection['SERVER'],
					'syncOffset' => time() - $calculateTimestamp($connection['SYNCHRONIZED']),
				];
			}
			else if($googleHelper->isGoogleConnection($connection['ACCOUNT_TYPE']))
			{
				$connections['google'] = [
					'type' => 'google',
					'id' => $connection['ID'],
					'active' => true,
					'connected' => true,
					'userName' => $connection['NAME'] ?? null,
					'connectionName' => $connection['NAME'],
					'status' => self::isConnectionSuccess($connection['LAST_RESULT']),
					'syncOffset' => time() - $calculateTimestamp($connection['SYNCHRONIZED']),
				];
			}
		}

		return $connections;
	}

	return null;
}