• Модуль: dav
  • Путь к файлу: ~/bitrix/modules/dav/classes/general/groupdavclientcalendar.php
  • Класс: CDavGroupdavClientCalendar
  • Вызов: CDavGroupdavClientCalendar::GetCalendarListByPath
private function GetCalendarListByPath($path = '/', $logger = null)
{
	$this->Connect();

	$result = $this->Propfind(
		$path,
		array(
			array("calendar-home-set", "urn:ietf:params:xml:ns:caldav"),
			array("getctag", "http://calendarserver.org/ns/"),
			"displayname",
			array("calendar-description", "urn:ietf:params:xml:ns:caldav"),
			array("calendar-color", "http://apple.com/ns/ical/"),
			array("supported-calendar-component-set", "urn:ietf:params:xml:ns:caldav"),
			"resourcetype",
			"owner",
			"current-user-principal",
			"principal-URL",
		),
		null,
		1,
		$logger
	);

	$this->Disconnect();

	if (is_null($result) || $this->getError())
	{
		return null;
	}

	$xmlDoc = $result->GetBodyXml();

	$arCalendars = [];
	$calendarHomeSet = null;
	$currentUserPrincipal = null;
	$principalUrl = null;

	$arResponse = $xmlDoc->GetPath("/*/response");

	foreach ($arResponse as $response)
	{
		$arResourceType = $response->GetPath("/response/propstat/prop/resourcetype/calendar");
		if (!empty($arResourceType))
		{
			$arHref = $response->GetPath("/response/href");
			if (!empty($arHref))
			{
				$arCalendar = [
					"href" => urldecode($arHref[0]->GetContent()),
				];

				$arProps = $response->GetPath("/response/propstat/prop/*");
				foreach ($arProps as $prop)
				{
					$s = $prop->GetContent();
					if (is_string($s) || is_numeric($s))
					{
						$arCalendar[$prop->GetTag()] = $this->Encode($s);
					}
					else if ($prop->GetTag() === 'supported-calendar-component-set')
					{
						$type = $s[0]->GetAttribute('name');
						if (is_string($type))
						{
							$arCalendar[$prop->GetTag()] = $this->Encode($type);
						}
					}
				}

				$arCalendars[] = $arCalendar;
			}
		}

		if (is_null($calendarHomeSet))
		{
			$arCalendarHomeSet = $response->GetPath("/response/propstat/prop/calendar-home-set/href");
			if (!empty($arCalendarHomeSet))
			{
				$calendarHomeSet = urldecode($arCalendarHomeSet[0]->GetContent());
			}
		}

		if (is_null($currentUserPrincipal))
		{
			$arCurrentUserPrincipal = $response->GetPath("/response/propstat/prop/current-user-principal/href");
			if (!empty($arCurrentUserPrincipal))
			{
				$currentUserPrincipal = urldecode($arCurrentUserPrincipal[0]->GetContent());
			}
		}

		if (is_null($principalUrl))
		{
			$arPrincipalUrl = $response->GetPath("/response/propstat/prop/principal-URL/href");
			if (!empty($arPrincipalUrl))
			{
				$principalUrl = urldecode($arPrincipalUrl[0]->GetContent());
			}
		}
	}

	if ($arCalendars)
	{
		return $arCalendars;
	}

	if (!is_null($calendarHomeSet) && ($path != $calendarHomeSet))
	{
		return $calendarHomeSet;
	}
	if (!is_null($principalUrl) && ($path != $principalUrl))
	{
		return $principalUrl;
	}
	if (!is_null($currentUserPrincipal) && ($path != $currentUserPrincipal))
	{
		return $currentUserPrincipal;
	}

	return null;
}