aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV/CachedSubscriptionProvider.php
blob: d64f039d05b79b6d70d22f26f41d1afefec2965d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\DAV\CalDAV;

use OCP\Calendar\ICalendarProvider;

class CachedSubscriptionProvider implements ICalendarProvider {

	public function __construct(
		private CalDavBackend $calDavBackend,
	) {
	}

	public function getCalendars(string $principalUri, array $calendarUris = []): array {
		$calendarInfos = $this->calDavBackend->getSubscriptionsForUser($principalUri);

		if (count($calendarUris) > 0) {
			$calendarInfos = array_filter($calendarInfos, fn (array $subscription) => in_array($subscription['uri'], $calendarUris));
		}

		$calendarInfos = array_values(array_filter($calendarInfos));

		$iCalendars = [];
		foreach ($calendarInfos as $calendarInfo) {
			$calendar = new CachedSubscription($this->calDavBackend, $calendarInfo);
			$iCalendars[] = new CachedSubscriptionImpl(
				$calendar,
				$calendarInfo,
				$this->calDavBackend,
			);
		}
		return $iCalendars;
	}
}