CachedSubscriptionProvider.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. use OCP\Calendar\ICalendarProvider;
  9. class CachedSubscriptionProvider implements ICalendarProvider {
  10. public function __construct(
  11. private CalDavBackend $calDavBackend
  12. ) {
  13. }
  14. public function getCalendars(string $principalUri, array $calendarUris = []): array {
  15. $calendarInfos = $this->calDavBackend->getSubscriptionsForUser($principalUri);
  16. if (count($calendarUris) > 0) {
  17. $calendarInfos = array_filter($calendarInfos, fn (array $subscription) => in_array($subscription['uri'], $calendarUris));
  18. }
  19. $calendarInfos = array_values(array_filter($calendarInfos));
  20. $iCalendars = [];
  21. foreach ($calendarInfos as $calendarInfo) {
  22. $calendar = new CachedSubscription($this->calDavBackend, $calendarInfo);
  23. $iCalendars[] = new CachedSubscriptionImpl(
  24. $calendar,
  25. $calendarInfo,
  26. $this->calDavBackend,
  27. );
  28. }
  29. return $iCalendars;
  30. }
  31. }