Invite.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Property;
  4. use Sabre\CalDAV\Plugin;
  5. use Sabre\DAV;
  6. use Sabre\DAV\Xml\Element\Sharee;
  7. use Sabre\Xml\Writer;
  8. use Sabre\Xml\XmlSerializable;
  9. /**
  10. * Invite property.
  11. *
  12. * This property encodes the 'invite' property, as defined by
  13. * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
  14. * namespace.
  15. *
  16. * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
  17. *
  18. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  19. * @author Evert Pot (http://evertpot.com/)
  20. * @license http://sabre.io/license/ Modified BSD License
  21. */
  22. class Invite implements XmlSerializable
  23. {
  24. /**
  25. * The list of users a calendar has been shared to.
  26. *
  27. * @var Sharee[]
  28. */
  29. protected $sharees;
  30. /**
  31. * Creates the property.
  32. *
  33. * @param Sharee[] $sharees
  34. */
  35. public function __construct(array $sharees)
  36. {
  37. $this->sharees = $sharees;
  38. }
  39. /**
  40. * Returns the list of users, as it was passed to the constructor.
  41. *
  42. * @return array
  43. */
  44. public function getValue()
  45. {
  46. return $this->sharees;
  47. }
  48. /**
  49. * The xmlSerialize method is called during xml writing.
  50. *
  51. * Use the $writer argument to write its own xml serialization.
  52. *
  53. * An important note: do _not_ create a parent element. Any element
  54. * implementing XmlSerializable should only ever write what's considered
  55. * its 'inner xml'.
  56. *
  57. * The parent of the current element is responsible for writing a
  58. * containing element.
  59. *
  60. * This allows serializers to be re-used for different element names.
  61. *
  62. * If you are opening new elements, you must also close them again.
  63. */
  64. public function xmlSerialize(Writer $writer)
  65. {
  66. $cs = '{'.Plugin::NS_CALENDARSERVER.'}';
  67. foreach ($this->sharees as $sharee) {
  68. if (DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $sharee->access) {
  69. $writer->startElement($cs.'organizer');
  70. } else {
  71. $writer->startElement($cs.'user');
  72. switch ($sharee->inviteStatus) {
  73. case DAV\Sharing\Plugin::INVITE_ACCEPTED:
  74. $writer->writeElement($cs.'invite-accepted');
  75. break;
  76. case DAV\Sharing\Plugin::INVITE_DECLINED:
  77. $writer->writeElement($cs.'invite-declined');
  78. break;
  79. case DAV\Sharing\Plugin::INVITE_NORESPONSE:
  80. $writer->writeElement($cs.'invite-noresponse');
  81. break;
  82. case DAV\Sharing\Plugin::INVITE_INVALID:
  83. $writer->writeElement($cs.'invite-invalid');
  84. break;
  85. }
  86. $writer->startElement($cs.'access');
  87. switch ($sharee->access) {
  88. case DAV\Sharing\Plugin::ACCESS_READWRITE:
  89. $writer->writeElement($cs.'read-write');
  90. break;
  91. case DAV\Sharing\Plugin::ACCESS_READ:
  92. $writer->writeElement($cs.'read');
  93. break;
  94. }
  95. $writer->endElement(); // access
  96. }
  97. $href = new DAV\Xml\Property\Href($sharee->href);
  98. $href->xmlSerialize($writer);
  99. if (isset($sharee->properties['{DAV:}displayname'])) {
  100. $writer->writeElement($cs.'common-name', $sharee->properties['{DAV:}displayname']);
  101. }
  102. if ($sharee->comment) {
  103. $writer->writeElement($cs.'summary', $sharee->comment);
  104. }
  105. $writer->endElement(); // organizer or user
  106. }
  107. }
  108. }