CalendarHome.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\CalDAV;
  24. use Sabre\CalDAV\Backend\BackendInterface;
  25. use Sabre\CalDAV\Backend\NotificationSupport;
  26. use Sabre\CalDAV\Backend\SchedulingSupport;
  27. use Sabre\CalDAV\Backend\SubscriptionSupport;
  28. use Sabre\CalDAV\Schedule\Inbox;
  29. use Sabre\CalDAV\Schedule\Outbox;
  30. use Sabre\CalDAV\Subscriptions\Subscription;
  31. use Sabre\DAV\Exception\NotFound;
  32. class CalendarHome extends \Sabre\CalDAV\CalendarHome {
  33. /** @var \OCP\IL10N */
  34. private $l10n;
  35. public function __construct(BackendInterface $caldavBackend, $principalInfo) {
  36. parent::__construct($caldavBackend, $principalInfo);
  37. $this->l10n = \OC::$server->getL10N('dav');
  38. }
  39. /**
  40. * @return BackendInterface
  41. */
  42. public function getCalDAVBackend() {
  43. return $this->caldavBackend;
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. function getChildren() {
  49. $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
  50. $objects = [];
  51. foreach ($calendars as $calendar) {
  52. $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
  53. }
  54. if ($this->caldavBackend instanceof SchedulingSupport) {
  55. $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  56. $objects[] = new Outbox($this->principalInfo['uri']);
  57. }
  58. // We're adding a notifications node, if it's supported by the backend.
  59. if ($this->caldavBackend instanceof NotificationSupport) {
  60. $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  61. }
  62. // If the backend supports subscriptions, we'll add those as well,
  63. if ($this->caldavBackend instanceof SubscriptionSupport) {
  64. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  65. $objects[] = new Subscription($this->caldavBackend, $subscription);
  66. }
  67. }
  68. return $objects;
  69. }
  70. /**
  71. * @inheritdoc
  72. */
  73. function getChild($name) {
  74. // Special nodes
  75. if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
  76. return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  77. }
  78. if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
  79. return new Outbox($this->principalInfo['uri']);
  80. }
  81. if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
  82. return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  83. }
  84. // Calendars
  85. foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
  86. if ($calendar['uri'] === $name) {
  87. return new Calendar($this->caldavBackend, $calendar, $this->l10n);
  88. }
  89. }
  90. if ($this->caldavBackend instanceof SubscriptionSupport) {
  91. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  92. if ($subscription['uri'] === $name) {
  93. return new Subscription($this->caldavBackend, $subscription);
  94. }
  95. }
  96. }
  97. throw new NotFound('Node with name \'' . $name . '\' could not be found');
  98. }
  99. }