1
0

CalendarManager.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /** @var CalDavBackend */
  13. private $backend;
  14. /** @var IL10N */
  15. private $l10n;
  16. /** @var IConfig */
  17. private $config;
  18. /** @var LoggerInterface */
  19. private $logger;
  20. /**
  21. * CalendarManager constructor.
  22. *
  23. * @param CalDavBackend $backend
  24. * @param IL10N $l10n
  25. * @param IConfig $config
  26. */
  27. public function __construct(CalDavBackend $backend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
  28. $this->backend = $backend;
  29. $this->l10n = $l10n;
  30. $this->config = $config;
  31. $this->logger = $logger;
  32. }
  33. /**
  34. * @param IManager $cm
  35. * @param string $userId
  36. */
  37. public function setupCalendarProvider(IManager $cm, $userId) {
  38. $calendars = $this->backend->getCalendarsForUser("principals/users/$userId");
  39. $this->register($cm, $calendars);
  40. }
  41. /**
  42. * @param IManager $cm
  43. * @param array $calendars
  44. */
  45. private function register(IManager $cm, array $calendars) {
  46. foreach ($calendars as $calendarInfo) {
  47. $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  48. $cm->registerCalendar(new CalendarImpl(
  49. $calendar,
  50. $calendarInfo,
  51. $this->backend
  52. ));
  53. }
  54. }
  55. }