Invite.php 4.9 KB

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