CalendarRoot.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\CalDAV;
  27. use Psr\Log\LoggerInterface;
  28. use Sabre\CalDAV\Backend;
  29. use Sabre\DAVACL\PrincipalBackend;
  30. class CalendarRoot extends \Sabre\CalDAV\CalendarRoot {
  31. private LoggerInterface $logger;
  32. private array $returnCachedSubscriptions = [];
  33. public function __construct(
  34. PrincipalBackend\BackendInterface $principalBackend,
  35. Backend\BackendInterface $caldavBackend,
  36. $principalPrefix,
  37. LoggerInterface $logger
  38. ) {
  39. parent::__construct($principalBackend, $caldavBackend, $principalPrefix);
  40. $this->logger = $logger;
  41. }
  42. public function getChildForPrincipal(array $principal) {
  43. return new CalendarHome(
  44. $this->caldavBackend,
  45. $principal,
  46. $this->logger,
  47. array_key_exists($principal['uri'], $this->returnCachedSubscriptions)
  48. );
  49. }
  50. public function getName() {
  51. if ($this->principalPrefix === 'principals/calendar-resources' ||
  52. $this->principalPrefix === 'principals/calendar-rooms') {
  53. $parts = explode('/', $this->principalPrefix);
  54. return $parts[1];
  55. }
  56. return parent::getName();
  57. }
  58. public function enableReturnCachedSubscriptions(string $principalUri): void {
  59. $this->returnCachedSubscriptions['principals/users/' . $principalUri] = true;
  60. }
  61. }