1
0

CalendarProvider.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 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. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use Psr\Log\LoggerInterface;
  12. class CalendarProvider implements ICalendarProvider {
  13. public function __construct(
  14. private CalDavBackend $calDavBackend,
  15. private IL10N $l10n,
  16. private IConfig $config,
  17. private LoggerInterface $logger,
  18. ) {
  19. }
  20. public function getCalendars(string $principalUri, array $calendarUris = []): array {
  21. $calendarInfos = $this->calDavBackend->getCalendarsForUser($principalUri) ?? [];
  22. if (!empty($calendarUris)) {
  23. $calendarInfos = array_filter($calendarInfos, function ($calendar) use ($calendarUris) {
  24. return in_array($calendar['uri'], $calendarUris);
  25. });
  26. }
  27. $iCalendars = [];
  28. foreach ($calendarInfos as $calendarInfo) {
  29. $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  30. $iCalendars[] = new CalendarImpl(
  31. $calendar,
  32. $calendarInfo,
  33. $this->calDavBackend,
  34. );
  35. }
  36. return $iCalendars;
  37. }
  38. }