Collection.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace Sabre\CalDAV\Notifications;
  3. use Sabre\DAV;
  4. use Sabre\CalDAV;
  5. use Sabre\DAVACL;
  6. /**
  7. * This node represents a list of notifications.
  8. *
  9. * It provides no additional functionality, but you must implement this
  10. * interface to allow the Notifications plugin to mark the collection
  11. * as a notifications collection.
  12. *
  13. * This collection should only return Sabre\CalDAV\Notifications\INode nodes as
  14. * its children.
  15. *
  16. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  17. * @author Evert Pot (http://evertpot.com/)
  18. * @license http://sabre.io/license/ Modified BSD License
  19. */
  20. class Collection extends DAV\Collection implements ICollection, DAVACL\IACL {
  21. /**
  22. * The notification backend
  23. *
  24. * @var Sabre\CalDAV\Backend\NotificationSupport
  25. */
  26. protected $caldavBackend;
  27. /**
  28. * Principal uri
  29. *
  30. * @var string
  31. */
  32. protected $principalUri;
  33. /**
  34. * Constructor
  35. *
  36. * @param CalDAV\Backend\NotificationSupport $caldavBackend
  37. * @param string $principalUri
  38. */
  39. function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri) {
  40. $this->caldavBackend = $caldavBackend;
  41. $this->principalUri = $principalUri;
  42. }
  43. /**
  44. * Returns all notifications for a principal
  45. *
  46. * @return array
  47. */
  48. function getChildren() {
  49. $children = [];
  50. $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);
  51. foreach ($notifications as $notification) {
  52. $children[] = new Node(
  53. $this->caldavBackend,
  54. $this->principalUri,
  55. $notification
  56. );
  57. }
  58. return $children;
  59. }
  60. /**
  61. * Returns the name of this object
  62. *
  63. * @return string
  64. */
  65. function getName() {
  66. return 'notifications';
  67. }
  68. /**
  69. * Returns the owner principal
  70. *
  71. * This must be a url to a principal, or null if there's no owner
  72. *
  73. * @return string|null
  74. */
  75. function getOwner() {
  76. return $this->principalUri;
  77. }
  78. /**
  79. * Returns a group principal
  80. *
  81. * This must be a url to a principal, or null if there's no owner
  82. *
  83. * @return string|null
  84. */
  85. function getGroup() {
  86. return null;
  87. }
  88. /**
  89. * Returns a list of ACE's for this node.
  90. *
  91. * Each ACE has the following properties:
  92. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  93. * currently the only supported privileges
  94. * * 'principal', a url to the principal who owns the node
  95. * * 'protected' (optional), indicating that this ACE is not allowed to
  96. * be updated.
  97. *
  98. * @return array
  99. */
  100. function getACL() {
  101. return [
  102. [
  103. 'principal' => $this->getOwner(),
  104. 'privilege' => '{DAV:}read',
  105. 'protected' => true,
  106. ],
  107. [
  108. 'principal' => $this->getOwner(),
  109. 'privilege' => '{DAV:}write',
  110. 'protected' => true,
  111. ]
  112. ];
  113. }
  114. /**
  115. * Updates the ACL
  116. *
  117. * This method will receive a list of new ACE's as an array argument.
  118. *
  119. * @param array $acl
  120. * @return void
  121. */
  122. function setACL(array $acl) {
  123. throw new DAV\Exception\NotImplemented('Updating ACLs is not implemented here');
  124. }
  125. /**
  126. * Returns the list of supported privileges for this node.
  127. *
  128. * The returned data structure is a list of nested privileges.
  129. * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
  130. * standard structure.
  131. *
  132. * If null is returned from this method, the default privilege set is used,
  133. * which is fine for most common usecases.
  134. *
  135. * @return array|null
  136. */
  137. function getSupportedPrivilegeSet() {
  138. return null;
  139. }
  140. }