SchedulingObject.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace Sabre\CalDAV\Schedule;
  3. use Sabre\CalDAV\Backend;
  4. use Sabre\DAV\Exception\MethodNotAllowed;
  5. /**
  6. * The SchedulingObject represents a scheduling object in the Inbox collection
  7. *
  8. * @author Brett (https://github.com/bretten)
  9. * @license http://sabre.io/license/ Modified BSD License
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. */
  12. class SchedulingObject extends \Sabre\CalDAV\CalendarObject implements ISchedulingObject {
  13. /**
  14. /* The CalDAV backend
  15. *
  16. * @var Backend\SchedulingSupport
  17. */
  18. protected $caldavBackend;
  19. /**
  20. * Array with information about this SchedulingObject
  21. *
  22. * @var array
  23. */
  24. protected $objectData;
  25. /**
  26. * Constructor
  27. *
  28. * The following properties may be passed within $objectData:
  29. *
  30. * * uri - A unique uri. Only the 'basename' must be passed.
  31. * * principaluri - the principal that owns the object.
  32. * * calendardata (optional) - The iCalendar data
  33. * * etag - (optional) The etag for this object, MUST be encloded with
  34. * double-quotes.
  35. * * size - (optional) The size of the data in bytes.
  36. * * lastmodified - (optional) format as a unix timestamp.
  37. * * acl - (optional) Use this to override the default ACL for the node.
  38. *
  39. * @param Backend\BackendInterface $caldavBackend
  40. * @param array $objectData
  41. */
  42. function __construct(Backend\SchedulingSupport $caldavBackend, array $objectData) {
  43. $this->caldavBackend = $caldavBackend;
  44. if (!isset($objectData['uri'])) {
  45. throw new \InvalidArgumentException('The objectData argument must contain an \'uri\' property');
  46. }
  47. $this->objectData = $objectData;
  48. }
  49. /**
  50. * Returns the ICalendar-formatted object
  51. *
  52. * @return string
  53. */
  54. function get() {
  55. // Pre-populating the 'calendardata' is optional, if we don't have it
  56. // already we fetch it from the backend.
  57. if (!isset($this->objectData['calendardata'])) {
  58. $this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
  59. }
  60. return $this->objectData['calendardata'];
  61. }
  62. /**
  63. * Updates the ICalendar-formatted object
  64. *
  65. * @param string|resource $calendarData
  66. * @return string
  67. */
  68. function put($calendarData) {
  69. throw new MethodNotAllowed('Updating scheduling objects is not supported');
  70. }
  71. /**
  72. * Deletes the scheduling message
  73. *
  74. * @return void
  75. */
  76. function delete() {
  77. $this->caldavBackend->deleteSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
  78. }
  79. /**
  80. * Returns the owner principal
  81. *
  82. * This must be a url to a principal, or null if there's no owner
  83. *
  84. * @return string|null
  85. */
  86. function getOwner() {
  87. return $this->objectData['principaluri'];
  88. }
  89. /**
  90. * Returns a list of ACE's for this node.
  91. *
  92. * Each ACE has the following properties:
  93. * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
  94. * currently the only supported privileges
  95. * * 'principal', a url to the principal who owns the node
  96. * * 'protected' (optional), indicating that this ACE is not allowed to
  97. * be updated.
  98. *
  99. * @return array
  100. */
  101. function getACL() {
  102. // An alternative acl may be specified in the object data.
  103. //
  104. if (isset($this->objectData['acl'])) {
  105. return $this->objectData['acl'];
  106. }
  107. // The default ACL
  108. return [
  109. [
  110. 'privilege' => '{DAV:}read',
  111. 'principal' => $this->objectData['principaluri'],
  112. 'protected' => true,
  113. ],
  114. [
  115. 'privilege' => '{DAV:}write',
  116. 'principal' => $this->objectData['principaluri'],
  117. 'protected' => true,
  118. ],
  119. [
  120. 'privilege' => '{DAV:}read',
  121. 'principal' => $this->objectData['principaluri'] . '/calendar-proxy-write',
  122. 'protected' => true,
  123. ],
  124. [
  125. 'privilege' => '{DAV:}write',
  126. 'principal' => $this->objectData['principaluri'] . '/calendar-proxy-write',
  127. 'protected' => true,
  128. ],
  129. [
  130. 'privilege' => '{DAV:}read',
  131. 'principal' => $this->objectData['principaluri'] . '/calendar-proxy-read',
  132. 'protected' => true,
  133. ],
  134. ];
  135. }
  136. }