Invite.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * Creates the property.
  27. *
  28. * Users is an array. Each element of the array has the following
  29. * properties:
  30. *
  31. * * href - Often a mailto: address
  32. * * commonName - Optional, for example a first and lastname for a user.
  33. * * status - One of the SharingPlugin::STATUS_* constants.
  34. * * readOnly - true or false
  35. * * summary - Optional, description of the share
  36. *
  37. * The organizer key is optional to specify. It's only useful when a
  38. * 'sharee' requests the sharing information.
  39. *
  40. * The organizer may have the following properties:
  41. * * href - Often a mailto: address.
  42. * * commonName - Optional human-readable name.
  43. * * firstName - Optional first name.
  44. * * lastName - Optional last name.
  45. *
  46. * If you wonder why these two structures are so different, I guess a
  47. * valid answer is that the current spec is still a draft.
  48. *
  49. * @param array $users
  50. */
  51. public function __construct(
  52. /**
  53. * The list of users a calendar has been shared to.
  54. */
  55. protected array $users,
  56. /**
  57. * The organizer contains information about the person who shared the
  58. * object.
  59. */
  60. protected ?array $organizer = null,
  61. ) {
  62. }
  63. /**
  64. * Returns the list of users, as it was passed to the constructor.
  65. *
  66. * @return array
  67. */
  68. public function getValue() {
  69. return $this->users;
  70. }
  71. /**
  72. * The xmlSerialize method is called during xml writing.
  73. *
  74. * Use the $writer argument to write its own xml serialization.
  75. *
  76. * An important note: do _not_ create a parent element. Any element
  77. * implementing XmlSerializble should only ever write what's considered
  78. * its 'inner xml'.
  79. *
  80. * The parent of the current element is responsible for writing a
  81. * containing element.
  82. *
  83. * This allows serializers to be re-used for different element names.
  84. *
  85. * If you are opening new elements, you must also close them again.
  86. *
  87. * @param Writer $writer
  88. * @return void
  89. */
  90. public function xmlSerialize(Writer $writer) {
  91. $cs = '{' . Plugin::NS_OWNCLOUD . '}';
  92. if (!is_null($this->organizer)) {
  93. $writer->startElement($cs . 'organizer');
  94. $writer->writeElement('{DAV:}href', $this->organizer['href']);
  95. if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
  96. $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
  97. }
  98. if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
  99. $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
  100. }
  101. if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
  102. $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
  103. }
  104. $writer->endElement(); // organizer
  105. }
  106. foreach ($this->users as $user) {
  107. $writer->startElement($cs . 'user');
  108. $writer->writeElement('{DAV:}href', $user['href']);
  109. if (isset($user['commonName']) && $user['commonName']) {
  110. $writer->writeElement($cs . 'common-name', $user['commonName']);
  111. }
  112. $writer->writeElement($cs . 'invite-accepted');
  113. $writer->startElement($cs . 'access');
  114. if ($user['readOnly']) {
  115. $writer->writeElement($cs . 'read');
  116. } else {
  117. $writer->writeElement($cs . 'read-write');
  118. }
  119. $writer->endElement(); // access
  120. if (isset($user['summary']) && $user['summary']) {
  121. $writer->writeElement($cs . 'summary', $user['summary']);
  122. }
  123. $writer->endElement(); //user
  124. }
  125. }
  126. }