CalendarRoot.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. use Psr\Log\LoggerInterface;
  9. use Sabre\CalDAV\Backend;
  10. use Sabre\DAVACL\PrincipalBackend;
  11. class CalendarRoot extends \Sabre\CalDAV\CalendarRoot {
  12. private LoggerInterface $logger;
  13. private array $returnCachedSubscriptions = [];
  14. public function __construct(
  15. PrincipalBackend\BackendInterface $principalBackend,
  16. Backend\BackendInterface $caldavBackend,
  17. $principalPrefix,
  18. LoggerInterface $logger
  19. ) {
  20. parent::__construct($principalBackend, $caldavBackend, $principalPrefix);
  21. $this->logger = $logger;
  22. }
  23. public function getChildForPrincipal(array $principal) {
  24. return new CalendarHome(
  25. $this->caldavBackend,
  26. $principal,
  27. $this->logger,
  28. array_key_exists($principal['uri'], $this->returnCachedSubscriptions)
  29. );
  30. }
  31. public function getName() {
  32. if ($this->principalPrefix === 'principals/calendar-resources' ||
  33. $this->principalPrefix === 'principals/calendar-rooms') {
  34. $parts = explode('/', $this->principalPrefix);
  35. return $parts[1];
  36. }
  37. return parent::getName();
  38. }
  39. public function enableReturnCachedSubscriptions(string $principalUri): void {
  40. $this->returnCachedSubscriptions['principals/users/' . $principalUri] = true;
  41. }
  42. }