CalendarManager.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\CalDAV;
  7. use OCP\Calendar\IManager;
  8. use OCP\IConfig;
  9. use OCP\IL10N;
  10. use Psr\Log\LoggerInterface;
  11. class CalendarManager {
  12. /**
  13. * CalendarManager constructor.
  14. *
  15. * @param CalDavBackend $backend
  16. * @param IL10N $l10n
  17. * @param IConfig $config
  18. */
  19. public function __construct(
  20. private CalDavBackend $backend,
  21. private IL10N $l10n,
  22. private IConfig $config,
  23. private LoggerInterface $logger,
  24. ) {
  25. }
  26. /**
  27. * @param IManager $cm
  28. * @param string $userId
  29. */
  30. public function setupCalendarProvider(IManager $cm, $userId) {
  31. $calendars = $this->backend->getCalendarsForUser("principals/users/$userId");
  32. $this->register($cm, $calendars);
  33. }
  34. /**
  35. * @param IManager $cm
  36. * @param array $calendars
  37. */
  38. private function register(IManager $cm, array $calendars) {
  39. foreach ($calendars as $calendarInfo) {
  40. $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  41. $cm->registerCalendar(new CalendarImpl(
  42. $calendar,
  43. $calendarInfo,
  44. $this->backend
  45. ));
  46. }
  47. }
  48. }