Invite.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  5. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  6. *
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\DAV\DAV\Sharing\Xml;
  28. use OCA\DAV\DAV\Sharing\Plugin;
  29. use Sabre\Xml\Writer;
  30. use Sabre\Xml\XmlSerializable;
  31. /**
  32. * Invite property
  33. *
  34. * This property encodes the 'invite' property, as defined by
  35. * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
  36. * namespace.
  37. *
  38. * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
  39. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  40. * @author Evert Pot (http://evertpot.com/)
  41. * @license http://sabre.io/license/ Modified BSD License
  42. */
  43. class Invite implements XmlSerializable {
  44. /**
  45. * The list of users a calendar has been shared to.
  46. *
  47. * @var array
  48. */
  49. protected $users;
  50. /**
  51. * The organizer contains information about the person who shared the
  52. * object.
  53. *
  54. * @var array|null
  55. */
  56. protected $organizer;
  57. /**
  58. * Creates the property.
  59. *
  60. * Users is an array. Each element of the array has the following
  61. * properties:
  62. *
  63. * * href - Often a mailto: address
  64. * * commonName - Optional, for example a first and lastname for a user.
  65. * * status - One of the SharingPlugin::STATUS_* constants.
  66. * * readOnly - true or false
  67. * * summary - Optional, description of the share
  68. *
  69. * The organizer key is optional to specify. It's only useful when a
  70. * 'sharee' requests the sharing information.
  71. *
  72. * The organizer may have the following properties:
  73. * * href - Often a mailto: address.
  74. * * commonName - Optional human-readable name.
  75. * * firstName - Optional first name.
  76. * * lastName - Optional last name.
  77. *
  78. * If you wonder why these two structures are so different, I guess a
  79. * valid answer is that the current spec is still a draft.
  80. *
  81. * @param array $users
  82. */
  83. public function __construct(array $users, array $organizer = null) {
  84. $this->users = $users;
  85. $this->organizer = $organizer;
  86. }
  87. /**
  88. * Returns the list of users, as it was passed to the constructor.
  89. *
  90. * @return array
  91. */
  92. public function getValue() {
  93. return $this->users;
  94. }
  95. /**
  96. * The xmlSerialize method is called during xml writing.
  97. *
  98. * Use the $writer argument to write its own xml serialization.
  99. *
  100. * An important note: do _not_ create a parent element. Any element
  101. * implementing XmlSerializble should only ever write what's considered
  102. * its 'inner xml'.
  103. *
  104. * The parent of the current element is responsible for writing a
  105. * containing element.
  106. *
  107. * This allows serializers to be re-used for different element names.
  108. *
  109. * If you are opening new elements, you must also close them again.
  110. *
  111. * @param Writer $writer
  112. * @return void
  113. */
  114. public function xmlSerialize(Writer $writer) {
  115. $cs = '{' . Plugin::NS_OWNCLOUD . '}';
  116. if (!is_null($this->organizer)) {
  117. $writer->startElement($cs . 'organizer');
  118. $writer->writeElement('{DAV:}href', $this->organizer['href']);
  119. if (isset($this->organizer['commonName']) && $this->organizer['commonName']) {
  120. $writer->writeElement($cs . 'common-name', $this->organizer['commonName']);
  121. }
  122. if (isset($this->organizer['firstName']) && $this->organizer['firstName']) {
  123. $writer->writeElement($cs . 'first-name', $this->organizer['firstName']);
  124. }
  125. if (isset($this->organizer['lastName']) && $this->organizer['lastName']) {
  126. $writer->writeElement($cs . 'last-name', $this->organizer['lastName']);
  127. }
  128. $writer->endElement(); // organizer
  129. }
  130. foreach ($this->users as $user) {
  131. $writer->startElement($cs . 'user');
  132. $writer->writeElement('{DAV:}href', $user['href']);
  133. if (isset($user['commonName']) && $user['commonName']) {
  134. $writer->writeElement($cs . 'common-name', $user['commonName']);
  135. }
  136. $writer->writeElement($cs . 'invite-accepted');
  137. $writer->startElement($cs . 'access');
  138. if ($user['readOnly']) {
  139. $writer->writeElement($cs . 'read');
  140. } else {
  141. $writer->writeElement($cs . 'read-write');
  142. }
  143. $writer->endElement(); // access
  144. if (isset($user['summary']) && $user['summary']) {
  145. $writer->writeElement($cs . 'summary', $user['summary']);
  146. }
  147. $writer->endElement(); //user
  148. }
  149. }
  150. }