SchedulingObject.php 3.9 KB

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