1
0

CalendarProvider.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /** @var CalDavBackend */
  14. private $calDavBackend;
  15. /** @var IL10N */
  16. private $l10n;
  17. /** @var IConfig */
  18. private $config;
  19. /** @var LoggerInterface */
  20. private $logger;
  21. public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
  22. $this->calDavBackend = $calDavBackend;
  23. $this->l10n = $l10n;
  24. $this->config = $config;
  25. $this->logger = $logger;
  26. }
  27. public function getCalendars(string $principalUri, array $calendarUris = []): array {
  28. $calendarInfos = [];
  29. if (empty($calendarUris)) {
  30. $calendarInfos = $this->calDavBackend->getCalendarsForUser($principalUri);
  31. } else {
  32. foreach ($calendarUris as $calendarUri) {
  33. $calendarInfos[] = $this->calDavBackend->getCalendarByUri($principalUri, $calendarUri);
  34. }
  35. }
  36. $calendarInfos = array_filter($calendarInfos);
  37. $iCalendars = [];
  38. foreach ($calendarInfos as $calendarInfo) {
  39. $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  40. $iCalendars[] = new CalendarImpl(
  41. $calendar,
  42. $calendarInfo,
  43. $this->calDavBackend,
  44. );
  45. }
  46. return $iCalendars;
  47. }
  48. }