CalendarHome.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * @inheritdoc
  41. */
  42. function getChildren() {
  43. $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
  44. $objects = [];
  45. foreach ($calendars as $calendar) {
  46. $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
  47. }
  48. if ($this->caldavBackend instanceof SchedulingSupport) {
  49. $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  50. $objects[] = new Outbox($this->principalInfo['uri']);
  51. }
  52. // We're adding a notifications node, if it's supported by the backend.
  53. if ($this->caldavBackend instanceof NotificationSupport) {
  54. $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  55. }
  56. // If the backend supports subscriptions, we'll add those as well,
  57. if ($this->caldavBackend instanceof SubscriptionSupport) {
  58. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  59. $objects[] = new Subscription($this->caldavBackend, $subscription);
  60. }
  61. }
  62. return $objects;
  63. }
  64. /**
  65. * @inheritdoc
  66. */
  67. function getChild($name) {
  68. // Special nodes
  69. if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
  70. return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
  71. }
  72. if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
  73. return new Outbox($this->principalInfo['uri']);
  74. }
  75. if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
  76. return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
  77. }
  78. // Calendars
  79. foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
  80. if ($calendar['uri'] === $name) {
  81. return new Calendar($this->caldavBackend, $calendar, $this->l10n);
  82. }
  83. }
  84. if ($this->caldavBackend instanceof SubscriptionSupport) {
  85. foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
  86. if ($subscription['uri'] === $name) {
  87. return new Subscription($this->caldavBackend, $subscription);
  88. }
  89. }
  90. }
  91. throw new NotFound('Node with name \'' . $name . '\' could not be found');
  92. }
  93. }