You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarHome.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\CalDAV;
  26. use Sabre\CalDAV\Backend\BackendInterface;
  27. use Sabre\CalDAV\Backend\NotificationSupport;
  28. use Sabre\CalDAV\Backend\SchedulingSupport;
  29. use Sabre\CalDAV\Backend\SubscriptionSupport;
  30. use Sabre\CalDAV\Schedule\Inbox;
  31. use Sabre\CalDAV\Subscriptions\Subscription;
  32. use Sabre\DAV\Exception\NotFound;
  33. use Sabre\DAV\Exception\MethodNotAllowed;
  34. use Sabre\DAV\MkCol;
  35. class CalendarHome extends \Sabre\CalDAV\CalendarHome {
  36. /** @var \OCP\IL10N */
  37. private $l10n;
  38. /** @var \OCP\IConfig */
  39. private $config;
  40. /** @var bool */
  41. private $returnCachedSubscriptions=false;
  42. public function __construct(BackendInterface $caldavBackend, $principalInfo) {
  43. parent::__construct($caldavBackend, $principalInfo);
  44. $this->l10n = \OC::$server->getL10N('dav');
  45. $this->config = \OC::$server->getConfig();
  46. }
  47. /**
  48. * @return BackendInterface
  49. */
  50. public function getCalDAVBackend() {
  51. return $this->caldavBackend;
  52. }
  53. /**
  54. * @inheritdoc
  55. */
  56. function createExtendedCollection($name, MkCol $mkCol) {
  57. $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
  58. if (in_array($name, $reservedNames)) {
  59. throw new MethodNotAllowed('The resource you tried to create has a reserved name');
  60. }
  61. parent::createExtendedCollection($name, $mkCol);
  62. }
  63. /**
  64. * @inheritdoc
  65. */
  66. function getChildren() {
  67. $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
  68. $objects = [];
  69. foreach ($calendars as $calendar) {
  70. $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
  71. }
  72. if ($this->caldavBackend instanceof SchedulingSupport) {
  73. $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  74. $objects[] = new Outbox($this->config, $this->principalInfo['uri']);
  75. }
  76. // We're adding a notifications node, if it's supported by the backend.
  77. if ($this->caldavBackend instanceof NotificationSupport) {
  78. $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  79. }
  80. // If the backend supports subscriptions, we'll add those as well,
  81. if ($this->caldavBackend instanceof SubscriptionSupport) {
  82. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  83. if ($this->returnCachedSubscriptions) {
  84. $objects[] = new CachedSubscription($this->caldavBackend, $subscription);
  85. } else {
  86. $objects[] = new Subscription($this->caldavBackend, $subscription);
  87. }
  88. }
  89. }
  90. return $objects;
  91. }
  92. /**
  93. * @inheritdoc
  94. */
  95. function getChild($name) {
  96. // Special nodes
  97. if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
  98. return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  99. }
  100. if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
  101. return new Outbox($this->config, $this->principalInfo['uri']);
  102. }
  103. if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
  104. return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  105. }
  106. // Calendars
  107. foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
  108. if ($calendar['uri'] === $name) {
  109. return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
  110. }
  111. }
  112. if ($this->caldavBackend instanceof SubscriptionSupport) {
  113. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  114. if ($subscription['uri'] === $name) {
  115. if ($this->returnCachedSubscriptions) {
  116. return new CachedSubscription($this->caldavBackend, $subscription);
  117. }
  118. return new Subscription($this->caldavBackend, $subscription);
  119. }
  120. }
  121. }
  122. throw new NotFound('Node with name \'' . $name . '\' could not be found');
  123. }
  124. /**
  125. * @param array $filters
  126. * @param integer|null $limit
  127. * @param integer|null $offset
  128. */
  129. function calendarSearch(array $filters, $limit=null, $offset=null) {
  130. $principalUri = $this->principalInfo['uri'];
  131. return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
  132. }
  133. /**
  134. *
  135. */
  136. public function enableCachedSubscriptionsForThisRequest() {
  137. $this->returnCachedSubscriptions = true;
  138. }
  139. }