Invite.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-FileCopyrightText: fruux GmbH (https://fruux.com/)
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCA\DAV\DAV\Sharing\Xml;
  9. use OCA\DAV\DAV\Sharing\Plugin;
  10. use Sabre\Xml\Writer;
  11. use Sabre\Xml\XmlSerializable;
  12. /**
  13. * Invite property
  14. *
  15. * This property encodes the 'invite' property, as defined by
  16. * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
  17. * namespace.
  18. *
  19. * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
  20. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  21. * @author Evert Pot (http://evertpot.com/)
  22. * @license http://sabre.io/license/ Modified BSD License
  23. */
  24. class Invite implements XmlSerializable {
  25. /**
  26. * The list of users a calendar has been shared to.
  27. *
  28. * @var array
  29. */
  30. protected $users;
  31. /**
  32. * The organizer contains information about the person who shared the
  33. * object.
  34. *
  35. * @var array|null
  36. */
  37. protected $organizer;
  38. /**
  39. * Creates the property.
  40. *
  41. * Users is an array. Each element of the array has the following
  42. * properties:
  43. *
  44. * * href - Often a mailto: address
  45. * * commonName - Optional, for example a first and lastname for a user.
  46. * * status - One of the SharingPlugin::STATUS_* constants.
  47. * * readOnly - true or false
  48. * * summary - Optional, description of the share
  49. *
  50. * The organizer key is optional to specify. It's only useful when a
  51. * 'sharee' requests the sharing information.
  52. *
  53. * The organizer may have the following properties:
  54. * * href - Often a mailto: address.
  55. * * commonName - Optional human-readable name.
  56. * * firstName - Optional first name.
  57. * * lastName - Optional last name.
  58. *
  59. * If you wonder why these two structures are so different, I guess a
  60. * valid answer is that the current spec is still a draft.
  61. *
  62. * @param array $users
  63. */
  64. public function __construct(array $users, ?array $organizer = null) {
  65. $this->users = $users;
  66. $this->organizer = $organizer;
  67. }
  68. /**
  69. * Returns the list of users, as it was passed to the constructor.
  70. *
  71. * @return array
  72. */
  73. public function getValue() {
  74. return $this->users;
  75. }
  76. /**
  77. * The xmlSerialize method is called during xml writing.
  78. *
  79. * Use the $writer argument to write its own xml serialization.
  80. *
  81. * An important note: do _not_ create a parent element. Any element
  82. * implementing XmlSerializble should only ever write what's considered
  83. * its 'inner xml'.
  84. *
  85. * The parent of the current element is responsible for writing a
  86. * containing element.
  87. *
  88. * This allows serializers to be re-used for different element names.
  89. *
  90. * If you are opening new elements, you must also close them again.
  91. *
  92. * @param Writer $writer
  93. * @return void
  94. */
  95. public function xmlSerialize(Writer $writer) {
  96. $cs = '{' . Plugin::NS_OWNCLOUD . '}';
  97. if (!is_null($this->organizer)) {
  98. $writer->startElement($cs . 'organizer');
  99. $writer->writeElement('{DAV:}href', $this->organizer['href']);
  100. if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
  101. $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
  102. }
  103. if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
  104. $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
  105. }
  106. if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
  107. $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
  108. }
  109. $writer->endElement(); // organizer
  110. }
  111. foreach ($this->users as $user) {
  112. $writer->startElement($cs . 'user');
  113. $writer->writeElement('{DAV:}href', $user['href']);
  114. if (isset($user['commonName']) && $user['commonName']) {
  115. $writer->writeElement($cs . 'common-name', $user['commonName']);
  116. }
  117. $writer->writeElement($cs . 'invite-accepted');
  118. $writer->startElement($cs . 'access');
  119. if ($user['readOnly']) {
  120. $writer->writeElement($cs . 'read');
  121. } else {
  122. $writer->writeElement($cs . 'read-write');
  123. }
  124. $writer->endElement(); // access
  125. if (isset($user['summary']) && $user['summary']) {
  126. $writer->writeElement($cs . 'summary', $user['summary']);
  127. }
  128. $writer->endElement(); //user
  129. }
  130. }
  131. }