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