1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Xml\Notification; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\Xml\Writer; 6*a1a3b679SAndreas Boehleruse Sabre\CalDAV; 7*a1a3b679SAndreas Boehleruse Sabre\CalDAV\SharingPlugin; 8*a1a3b679SAndreas Boehler 9*a1a3b679SAndreas Boehler/** 10*a1a3b679SAndreas Boehler * This class represents the cs:invite-reply notification element. 11*a1a3b679SAndreas Boehler * 12*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 13*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 14*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 15*a1a3b679SAndreas Boehler */ 16*a1a3b679SAndreas Boehlerclass InviteReply implements NotificationInterface { 17*a1a3b679SAndreas Boehler 18*a1a3b679SAndreas Boehler /** 19*a1a3b679SAndreas Boehler * A unique id for the message 20*a1a3b679SAndreas Boehler * 21*a1a3b679SAndreas Boehler * @var string 22*a1a3b679SAndreas Boehler */ 23*a1a3b679SAndreas Boehler protected $id; 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler /** 26*a1a3b679SAndreas Boehler * Timestamp of the notification 27*a1a3b679SAndreas Boehler * 28*a1a3b679SAndreas Boehler * @var DateTime 29*a1a3b679SAndreas Boehler */ 30*a1a3b679SAndreas Boehler protected $dtStamp; 31*a1a3b679SAndreas Boehler 32*a1a3b679SAndreas Boehler /** 33*a1a3b679SAndreas Boehler * The unique id of the notification this was a reply to. 34*a1a3b679SAndreas Boehler * 35*a1a3b679SAndreas Boehler * @var string 36*a1a3b679SAndreas Boehler */ 37*a1a3b679SAndreas Boehler protected $inReplyTo; 38*a1a3b679SAndreas Boehler 39*a1a3b679SAndreas Boehler /** 40*a1a3b679SAndreas Boehler * A url to the recipient of the original (!) notification. 41*a1a3b679SAndreas Boehler * 42*a1a3b679SAndreas Boehler * @var string 43*a1a3b679SAndreas Boehler */ 44*a1a3b679SAndreas Boehler protected $href; 45*a1a3b679SAndreas Boehler 46*a1a3b679SAndreas Boehler /** 47*a1a3b679SAndreas Boehler * The type of message, see the SharingPlugin::STATUS_ constants. 48*a1a3b679SAndreas Boehler * 49*a1a3b679SAndreas Boehler * @var int 50*a1a3b679SAndreas Boehler */ 51*a1a3b679SAndreas Boehler protected $type; 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler /** 54*a1a3b679SAndreas Boehler * A url to the shared calendar. 55*a1a3b679SAndreas Boehler * 56*a1a3b679SAndreas Boehler * @var string 57*a1a3b679SAndreas Boehler */ 58*a1a3b679SAndreas Boehler protected $hostUrl; 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler /** 61*a1a3b679SAndreas Boehler * A description of the share request 62*a1a3b679SAndreas Boehler * 63*a1a3b679SAndreas Boehler * @var string 64*a1a3b679SAndreas Boehler */ 65*a1a3b679SAndreas Boehler protected $summary; 66*a1a3b679SAndreas Boehler 67*a1a3b679SAndreas Boehler /** 68*a1a3b679SAndreas Boehler * Notification Etag 69*a1a3b679SAndreas Boehler * 70*a1a3b679SAndreas Boehler * @var string 71*a1a3b679SAndreas Boehler */ 72*a1a3b679SAndreas Boehler protected $etag; 73*a1a3b679SAndreas Boehler 74*a1a3b679SAndreas Boehler /** 75*a1a3b679SAndreas Boehler * Creates the Invite Reply Notification. 76*a1a3b679SAndreas Boehler * 77*a1a3b679SAndreas Boehler * This constructor receives an array with the following elements: 78*a1a3b679SAndreas Boehler * 79*a1a3b679SAndreas Boehler * * id - A unique id 80*a1a3b679SAndreas Boehler * * etag - The etag 81*a1a3b679SAndreas Boehler * * dtStamp - A DateTime object with a timestamp for the notification. 82*a1a3b679SAndreas Boehler * * inReplyTo - This should refer to the 'id' of the notification 83*a1a3b679SAndreas Boehler * this is a reply to. 84*a1a3b679SAndreas Boehler * * type - The type of notification, see SharingPlugin::STATUS_* 85*a1a3b679SAndreas Boehler * constants for details. 86*a1a3b679SAndreas Boehler * * hostUrl - A url to the shared calendar. 87*a1a3b679SAndreas Boehler * * summary - Description of the share, can be the same as the 88*a1a3b679SAndreas Boehler * calendar, but may also be modified (optional). 89*a1a3b679SAndreas Boehler * 90*a1a3b679SAndreas Boehler * @param array $values 91*a1a3b679SAndreas Boehler */ 92*a1a3b679SAndreas Boehler function __construct(array $values) { 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $required = [ 95*a1a3b679SAndreas Boehler 'id', 96*a1a3b679SAndreas Boehler 'etag', 97*a1a3b679SAndreas Boehler 'href', 98*a1a3b679SAndreas Boehler 'dtStamp', 99*a1a3b679SAndreas Boehler 'inReplyTo', 100*a1a3b679SAndreas Boehler 'type', 101*a1a3b679SAndreas Boehler 'hostUrl', 102*a1a3b679SAndreas Boehler ]; 103*a1a3b679SAndreas Boehler foreach ($required as $item) { 104*a1a3b679SAndreas Boehler if (!isset($values[$item])) { 105*a1a3b679SAndreas Boehler throw new \InvalidArgumentException($item . ' is a required constructor option'); 106*a1a3b679SAndreas Boehler } 107*a1a3b679SAndreas Boehler } 108*a1a3b679SAndreas Boehler 109*a1a3b679SAndreas Boehler foreach ($values as $key => $value) { 110*a1a3b679SAndreas Boehler if (!property_exists($this, $key)) { 111*a1a3b679SAndreas Boehler throw new \InvalidArgumentException('Unknown option: ' . $key); 112*a1a3b679SAndreas Boehler } 113*a1a3b679SAndreas Boehler $this->$key = $value; 114*a1a3b679SAndreas Boehler } 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler } 117*a1a3b679SAndreas Boehler 118*a1a3b679SAndreas Boehler /** 119*a1a3b679SAndreas Boehler * The xmlSerialize metod is called during xml writing. 120*a1a3b679SAndreas Boehler * 121*a1a3b679SAndreas Boehler * Use the $writer argument to write its own xml serialization. 122*a1a3b679SAndreas Boehler * 123*a1a3b679SAndreas Boehler * An important note: do _not_ create a parent element. Any element 124*a1a3b679SAndreas Boehler * implementing XmlSerializble should only ever write what's considered 125*a1a3b679SAndreas Boehler * its 'inner xml'. 126*a1a3b679SAndreas Boehler * 127*a1a3b679SAndreas Boehler * The parent of the current element is responsible for writing a 128*a1a3b679SAndreas Boehler * containing element. 129*a1a3b679SAndreas Boehler * 130*a1a3b679SAndreas Boehler * This allows serializers to be re-used for different element names. 131*a1a3b679SAndreas Boehler * 132*a1a3b679SAndreas Boehler * If you are opening new elements, you must also close them again. 133*a1a3b679SAndreas Boehler * 134*a1a3b679SAndreas Boehler * @param Writer $writer 135*a1a3b679SAndreas Boehler * @return void 136*a1a3b679SAndreas Boehler */ 137*a1a3b679SAndreas Boehler function xmlSerialize(Writer $writer) { 138*a1a3b679SAndreas Boehler 139*a1a3b679SAndreas Boehler $writer->writeElement('{' . CalDAV\Plugin::NS_CALENDARSERVER . '}invite-reply'); 140*a1a3b679SAndreas Boehler 141*a1a3b679SAndreas Boehler } 142*a1a3b679SAndreas Boehler 143*a1a3b679SAndreas Boehler /** 144*a1a3b679SAndreas Boehler * This method serializes the entire notification, as it is used in the 145*a1a3b679SAndreas Boehler * response body. 146*a1a3b679SAndreas Boehler * 147*a1a3b679SAndreas Boehler * @param Writer $writer 148*a1a3b679SAndreas Boehler * @return void 149*a1a3b679SAndreas Boehler */ 150*a1a3b679SAndreas Boehler function xmlSerializeFull(Writer $writer) { 151*a1a3b679SAndreas Boehler 152*a1a3b679SAndreas Boehler $cs = '{' . CalDAV\Plugin::NS_CALENDARSERVER . '}'; 153*a1a3b679SAndreas Boehler 154*a1a3b679SAndreas Boehler $this->dtStamp->setTimezone(new \DateTimezone('GMT')); 155*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z')); 156*a1a3b679SAndreas Boehler 157*a1a3b679SAndreas Boehler $writer->startElement($cs . 'invite-reply'); 158*a1a3b679SAndreas Boehler 159*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'uid', $this->id); 160*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'in-reply-to', $this->inReplyTo); 161*a1a3b679SAndreas Boehler $writer->writeElement('{DAV:}href', $this->href); 162*a1a3b679SAndreas Boehler 163*a1a3b679SAndreas Boehler switch ($this->type) { 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler case SharingPlugin::STATUS_ACCEPTED : 166*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'invite-accepted'); 167*a1a3b679SAndreas Boehler break; 168*a1a3b679SAndreas Boehler case SharingPlugin::STATUS_DECLINED : 169*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'invite-declined'); 170*a1a3b679SAndreas Boehler break; 171*a1a3b679SAndreas Boehler 172*a1a3b679SAndreas Boehler } 173*a1a3b679SAndreas Boehler 174*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'hosturl', [ 175*a1a3b679SAndreas Boehler '{DAV:}href' => $writer->contextUri . $this->hostUrl 176*a1a3b679SAndreas Boehler ]); 177*a1a3b679SAndreas Boehler 178*a1a3b679SAndreas Boehler if ($this->summary) { 179*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'summary', $this->summary); 180*a1a3b679SAndreas Boehler } 181*a1a3b679SAndreas Boehler $writer->endElement(); // invite-reply 182*a1a3b679SAndreas Boehler 183*a1a3b679SAndreas Boehler } 184*a1a3b679SAndreas Boehler 185*a1a3b679SAndreas Boehler /** 186*a1a3b679SAndreas Boehler * Returns a unique id for this notification 187*a1a3b679SAndreas Boehler * 188*a1a3b679SAndreas Boehler * This is just the base url. This should generally be some kind of unique 189*a1a3b679SAndreas Boehler * id. 190*a1a3b679SAndreas Boehler * 191*a1a3b679SAndreas Boehler * @return string 192*a1a3b679SAndreas Boehler */ 193*a1a3b679SAndreas Boehler function getId() { 194*a1a3b679SAndreas Boehler 195*a1a3b679SAndreas Boehler return $this->id; 196*a1a3b679SAndreas Boehler 197*a1a3b679SAndreas Boehler } 198*a1a3b679SAndreas Boehler 199*a1a3b679SAndreas Boehler /** 200*a1a3b679SAndreas Boehler * Returns the ETag for this notification. 201*a1a3b679SAndreas Boehler * 202*a1a3b679SAndreas Boehler * The ETag must be surrounded by literal double-quotes. 203*a1a3b679SAndreas Boehler * 204*a1a3b679SAndreas Boehler * @return string 205*a1a3b679SAndreas Boehler */ 206*a1a3b679SAndreas Boehler function getETag() { 207*a1a3b679SAndreas Boehler 208*a1a3b679SAndreas Boehler return $this->etag; 209*a1a3b679SAndreas Boehler 210*a1a3b679SAndreas Boehler } 211*a1a3b679SAndreas Boehler 212*a1a3b679SAndreas Boehler} 213