Node.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace Sabre\CalDAV\Notifications;
  3. use Sabre\DAV;
  4. use Sabre\CalDAV;
  5. use Sabre\CalDAV\Xml\Notification\NotificationInterface;
  6. use Sabre\DAVACL;
  7. /**
  8. * This node represents a single notification.
  9. *
  10. * The signature is mostly identical to that of Sabre\DAV\IFile, but the get() method
  11. * MUST return an xml document that matches the requirements of the
  12. * 'caldav-notifications.txt' spec.
  13. *
  14. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  15. * @author Evert Pot (http://evertpot.com/)
  16. * @license http://sabre.io/license/ Modified BSD License
  17. */
  18. class Node extends DAV\File implements INode, DAVACL\IACL {
  19. /**
  20. * The notification backend
  21. *
  22. * @var Sabre\CalDAV\Backend\NotificationSupport
  23. */
  24. protected $caldavBackend;
  25. /**
  26. * The actual notification
  27. *
  28. * @var Sabre\CalDAV\Notifications\INotificationType
  29. */
  30. protected $notification;
  31. /**
  32. * Owner principal of the notification
  33. *
  34. * @var string
  35. */
  36. protected $principalUri;
  37. /**
  38. * Constructor
  39. *
  40. * @param CalDAV\Backend\NotificationSupport $caldavBackend
  41. * @param string $principalUri
  42. * @param NotificationInterface $notification
  43. */
  44. function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification) {
  45. $this->caldavBackend = $caldavBackend;
  46. $this->principalUri = $principalUri;
  47. $this->notification = $notification;
  48. }
  49. /**
  50. * Returns the path name for this notification
  51. *
  52. * @return id
  53. */
  54. function getName() {
  55. return $this->notification->getId() . '.xml';
  56. }
  57. /**
  58. * Returns the etag for the notification.
  59. *
  60. * The etag must be surrounded by litteral double-quotes.
  61. *
  62. * @return string
  63. */
  64. function getETag() {
  65. return $this->notification->getETag();
  66. }
  67. /**
  68. * This method must return an xml element, using the
  69. * Sabre\CalDAV\Notifications\INotificationType classes.
  70. *
  71. * @return INotificationType
  72. */
  73. function getNotificationType() {
  74. return $this->notification;
  75. }
  76. /**
  77. * Deletes this notification
  78. *
  79. * @return void
  80. */
  81. function delete() {
  82. $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
  83. }
  84. /**
  85. * Returns the owner principal
  86. *
  87. * This must be a url to a principal, or null if there's no owner
  88. *
  89. * @return string|null
  90. */
  91. function getOwner() {
  92. return $this->principalUri;
  93. }
  94. /**
  95. * Returns a group principal
  96. *
  97. * This must be a url to a principal, or null if there's no owner
  98. *
  99. * @return string|null
  100. */
  101. function getGroup() {
  102. return null;
  103. }
  104. /**
  105. * Returns a list of ACE's for this node.
  106. *
  107. * Each ACE has the following properties:
  108. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  109. * currently the only supported privileges
  110. * * 'principal', a url to the principal who owns the node
  111. * * 'protected' (optional), indicating that this ACE is not allowed to
  112. * be updated.
  113. *
  114. * @return array
  115. */
  116. function getACL() {
  117. return [
  118. [
  119. 'principal' => $this->getOwner(),
  120. 'privilege' => '{DAV:}read',
  121. 'protected' => true,
  122. ],
  123. [
  124. 'principal' => $this->getOwner(),
  125. 'privilege' => '{DAV:}write',
  126. 'protected' => true,
  127. ]
  128. ];
  129. }
  130. /**
  131. * Updates the ACL
  132. *
  133. * This method will receive a list of new ACE's as an array argument.
  134. *
  135. * @param array $acl
  136. * @return void
  137. */
  138. function setACL(array $acl) {
  139. throw new DAV\Exception\NotImplemented('Updating ACLs is not implemented here');
  140. }
  141. /**
  142. * Returns the list of supported privileges for this node.
  143. *
  144. * The returned data structure is a list of nested privileges.
  145. * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
  146. * standard structure.
  147. *
  148. * If null is returned from this method, the default privilege set is used,
  149. * which is fine for most common usecases.
  150. *
  151. * @return array|null
  152. */
  153. function getSupportedPrivilegeSet() {
  154. return null;
  155. }
  156. }