CalendarHome.php 3.6 KB

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