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\Plugin; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehler/** 9*a1a3b679SAndreas Boehler * SystemStatus notification 10*a1a3b679SAndreas Boehler * 11*a1a3b679SAndreas Boehler * This notification can be used to indicate to the user that the system is 12*a1a3b679SAndreas Boehler * down. 13*a1a3b679SAndreas Boehler * 14*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 15*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 16*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 17*a1a3b679SAndreas Boehler */ 18*a1a3b679SAndreas Boehlerclass SystemStatus implements NotificationInterface { 19*a1a3b679SAndreas Boehler 20*a1a3b679SAndreas Boehler const TYPE_LOW = 1; 21*a1a3b679SAndreas Boehler const TYPE_MEDIUM = 2; 22*a1a3b679SAndreas Boehler const TYPE_HIGH = 3; 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler /** 25*a1a3b679SAndreas Boehler * A unique id 26*a1a3b679SAndreas Boehler * 27*a1a3b679SAndreas Boehler * @var string 28*a1a3b679SAndreas Boehler */ 29*a1a3b679SAndreas Boehler protected $id; 30*a1a3b679SAndreas Boehler 31*a1a3b679SAndreas Boehler /** 32*a1a3b679SAndreas Boehler * The type of alert. This should be one of the TYPE_ constants. 33*a1a3b679SAndreas Boehler * 34*a1a3b679SAndreas Boehler * @var int 35*a1a3b679SAndreas Boehler */ 36*a1a3b679SAndreas Boehler protected $type; 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler /** 39*a1a3b679SAndreas Boehler * A human-readable description of the problem. 40*a1a3b679SAndreas Boehler * 41*a1a3b679SAndreas Boehler * @var string 42*a1a3b679SAndreas Boehler */ 43*a1a3b679SAndreas Boehler protected $description; 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler /** 46*a1a3b679SAndreas Boehler * A url to a website with more information for the user. 47*a1a3b679SAndreas Boehler * 48*a1a3b679SAndreas Boehler * @var string 49*a1a3b679SAndreas Boehler */ 50*a1a3b679SAndreas Boehler protected $href; 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler /** 53*a1a3b679SAndreas Boehler * Notification Etag 54*a1a3b679SAndreas Boehler * 55*a1a3b679SAndreas Boehler * @var string 56*a1a3b679SAndreas Boehler */ 57*a1a3b679SAndreas Boehler protected $etag; 58*a1a3b679SAndreas Boehler 59*a1a3b679SAndreas Boehler /** 60*a1a3b679SAndreas Boehler * Creates the notification. 61*a1a3b679SAndreas Boehler * 62*a1a3b679SAndreas Boehler * Some kind of unique id should be provided. This is used to generate a 63*a1a3b679SAndreas Boehler * url. 64*a1a3b679SAndreas Boehler * 65*a1a3b679SAndreas Boehler * @param string $id 66*a1a3b679SAndreas Boehler * @param string $etag 67*a1a3b679SAndreas Boehler * @param int $type 68*a1a3b679SAndreas Boehler * @param string $description 69*a1a3b679SAndreas Boehler * @param string $href 70*a1a3b679SAndreas Boehler */ 71*a1a3b679SAndreas Boehler function __construct($id, $etag, $type = self::TYPE_HIGH, $description = null, $href = null) { 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler $this->id = $id; 74*a1a3b679SAndreas Boehler $this->type = $type; 75*a1a3b679SAndreas Boehler $this->description = $description; 76*a1a3b679SAndreas Boehler $this->href = $href; 77*a1a3b679SAndreas Boehler $this->etag = $etag; 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler } 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler /** 82*a1a3b679SAndreas Boehler * The serialize method is called during xml writing. 83*a1a3b679SAndreas Boehler * 84*a1a3b679SAndreas Boehler * It should use the $writer argument to encode this object into XML. 85*a1a3b679SAndreas Boehler * 86*a1a3b679SAndreas Boehler * Important note: it is not needed to create the parent element. The 87*a1a3b679SAndreas Boehler * parent element is already created, and we only have to worry about 88*a1a3b679SAndreas Boehler * attributes, child elements and text (if any). 89*a1a3b679SAndreas Boehler * 90*a1a3b679SAndreas Boehler * Important note 2: If you are writing any new elements, you are also 91*a1a3b679SAndreas Boehler * responsible for closing them. 92*a1a3b679SAndreas Boehler * 93*a1a3b679SAndreas Boehler * @param Writer $writer 94*a1a3b679SAndreas Boehler * @return void 95*a1a3b679SAndreas Boehler */ 96*a1a3b679SAndreas Boehler function xmlSerialize(Writer $writer) { 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler switch ($this->type) { 99*a1a3b679SAndreas Boehler case self::TYPE_LOW : 100*a1a3b679SAndreas Boehler $type = 'low'; 101*a1a3b679SAndreas Boehler break; 102*a1a3b679SAndreas Boehler case self::TYPE_MEDIUM : 103*a1a3b679SAndreas Boehler $type = 'medium'; 104*a1a3b679SAndreas Boehler break; 105*a1a3b679SAndreas Boehler default : 106*a1a3b679SAndreas Boehler case self::TYPE_HIGH : 107*a1a3b679SAndreas Boehler $type = 'high'; 108*a1a3b679SAndreas Boehler break; 109*a1a3b679SAndreas Boehler } 110*a1a3b679SAndreas Boehler 111*a1a3b679SAndreas Boehler $writer->startElement('{' . Plugin::NS_CALENDARSERVER . '}systemstatus'); 112*a1a3b679SAndreas Boehler $writer->writeAttribute('type', $type); 113*a1a3b679SAndreas Boehler $writer->endElement(); 114*a1a3b679SAndreas Boehler 115*a1a3b679SAndreas Boehler } 116*a1a3b679SAndreas Boehler 117*a1a3b679SAndreas Boehler /** 118*a1a3b679SAndreas Boehler * This method serializes the entire notification, as it is used in the 119*a1a3b679SAndreas Boehler * response body. 120*a1a3b679SAndreas Boehler * 121*a1a3b679SAndreas Boehler * @param Writer $writer 122*a1a3b679SAndreas Boehler * @return void 123*a1a3b679SAndreas Boehler */ 124*a1a3b679SAndreas Boehler function xmlSerializeFull(Writer $writer) { 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler $cs = '{' . Plugin::NS_CALENDARSERVER . '}'; 127*a1a3b679SAndreas Boehler switch ($this->type) { 128*a1a3b679SAndreas Boehler case self::TYPE_LOW : 129*a1a3b679SAndreas Boehler $type = 'low'; 130*a1a3b679SAndreas Boehler break; 131*a1a3b679SAndreas Boehler case self::TYPE_MEDIUM : 132*a1a3b679SAndreas Boehler $type = 'medium'; 133*a1a3b679SAndreas Boehler break; 134*a1a3b679SAndreas Boehler default : 135*a1a3b679SAndreas Boehler case self::TYPE_HIGH : 136*a1a3b679SAndreas Boehler $type = 'high'; 137*a1a3b679SAndreas Boehler break; 138*a1a3b679SAndreas Boehler } 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler $writer->startElement($cs . 'systemstatus'); 141*a1a3b679SAndreas Boehler $writer->writeAttribute('type', $type); 142*a1a3b679SAndreas Boehler 143*a1a3b679SAndreas Boehler 144*a1a3b679SAndreas Boehler if ($this->description) { 145*a1a3b679SAndreas Boehler $writer->writeElement($cs . 'description', $this->description); 146*a1a3b679SAndreas Boehler } 147*a1a3b679SAndreas Boehler if ($this->href) { 148*a1a3b679SAndreas Boehler $writer->writeElement('{DAV:}href', $this->href); 149*a1a3b679SAndreas Boehler } 150*a1a3b679SAndreas Boehler 151*a1a3b679SAndreas Boehler $writer->endElement(); // systemstatus 152*a1a3b679SAndreas Boehler 153*a1a3b679SAndreas Boehler } 154*a1a3b679SAndreas Boehler 155*a1a3b679SAndreas Boehler /** 156*a1a3b679SAndreas Boehler * Returns a unique id for this notification 157*a1a3b679SAndreas Boehler * 158*a1a3b679SAndreas Boehler * This is just the base url. This should generally be some kind of unique 159*a1a3b679SAndreas Boehler * id. 160*a1a3b679SAndreas Boehler * 161*a1a3b679SAndreas Boehler * @return string 162*a1a3b679SAndreas Boehler */ 163*a1a3b679SAndreas Boehler function getId() { 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler return $this->id; 166*a1a3b679SAndreas Boehler 167*a1a3b679SAndreas Boehler } 168*a1a3b679SAndreas Boehler 169*a1a3b679SAndreas Boehler /* 170*a1a3b679SAndreas Boehler * Returns the ETag for this notification. 171*a1a3b679SAndreas Boehler * 172*a1a3b679SAndreas Boehler * The ETag must be surrounded by literal double-quotes. 173*a1a3b679SAndreas Boehler * 174*a1a3b679SAndreas Boehler * @return string 175*a1a3b679SAndreas Boehler */ 176*a1a3b679SAndreas Boehler function getETag() { 177*a1a3b679SAndreas Boehler 178*a1a3b679SAndreas Boehler return $this->etag; 179*a1a3b679SAndreas Boehler 180*a1a3b679SAndreas Boehler } 181*a1a3b679SAndreas Boehler 182*a1a3b679SAndreas Boehler} 183