CalendarRoot.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 array $returnCachedSubscriptions = [];
  13. public function __construct(
  14. PrincipalBackend\BackendInterface $principalBackend,
  15. Backend\BackendInterface $caldavBackend,
  16. $principalPrefix,
  17. private LoggerInterface $logger,
  18. ) {
  19. parent::__construct($principalBackend, $caldavBackend, $principalPrefix);
  20. }
  21. public function getChildForPrincipal(array $principal) {
  22. return new CalendarHome(
  23. $this->caldavBackend,
  24. $principal,
  25. $this->logger,
  26. array_key_exists($principal['uri'], $this->returnCachedSubscriptions)
  27. );
  28. }
  29. public function getName() {
  30. if ($this->principalPrefix === 'principals/calendar-resources' ||
  31. $this->principalPrefix === 'principals/calendar-rooms') {
  32. $parts = explode('/', $this->principalPrefix);
  33. return $parts[1];
  34. }
  35. return parent::getName();
  36. }
  37. public function enableReturnCachedSubscriptions(string $principalUri): void {
  38. $this->returnCachedSubscriptions['principals/users/' . $principalUri] = true;
  39. }
  40. }