]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CalDAV/Notifications/Notification/SystemStatus.php
removed community home addon
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CalDAV / Notifications / Notification / SystemStatus.php
1 <?php
2
3 /**
4  * SystemStatus notification
5  *
6  * This notification can be used to indicate to the user that the system is
7  * down.
8  *
9  * @package Sabre
10  * @subpackage CalDAV
11  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12  * @author Evert Pot (http://www.rooftopsolutions.nl/)
13  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14  */
15 class Sabre_CalDAV_Notifications_Notification_SystemStatus extends Sabre_DAV_Property implements Sabre_CalDAV_Notifications_INotificationType {
16
17     const TYPE_LOW = 1;
18     const TYPE_MEDIUM = 2;
19     const TYPE_HIGH = 3;
20
21     /**
22      * A unique id
23      *
24      * @var string
25      */
26     protected $id;
27
28     /**
29      * The type of alert. This should be one of the TYPE_ constants.
30      *
31      * @var int
32      */
33     protected $type;
34
35     /**
36      * A human-readable description of the problem.
37      *
38      * @var string
39      */
40     protected $description;
41
42     /**
43      * A url to a website with more information for the user.
44      *
45      * @var string
46      */
47     protected $href;
48
49     /**
50      * Creates the notification.
51      *
52      * Some kind of unique id should be provided. This is used to generate a
53      * url.
54      *
55      * @param string $id
56      * @param int $type
57      * @param string $description
58      * @param string $href
59      */
60     public function __construct($id, $type = self::TYPE_HIGH, $description = null, $href = null) {
61
62         $this->id = $id;
63         $this->type = $type;
64         $this->description = $description;
65         $this->href = $href;
66
67     }
68
69     /**
70      * Serializes the notification as a single property.
71      *
72      * You should usually just encode the single top-level element of the
73      * notification.
74      *
75      * @param Sabre_DAV_Server $server
76      * @param DOMElement $node
77      * @return void
78      */
79     public function serialize(Sabre_DAV_Server $server, \DOMElement $node) {
80
81         switch($this->type) {
82             case self::TYPE_LOW :
83                 $type = 'low';
84                 break;
85             case self::TYPE_MEDIUM :
86                 $type = 'medium';
87                 break;
88             default :
89             case self::TYPE_HIGH :
90                 $type = 'high';
91                 break;
92         }
93
94         $prop = $node->ownerDocument->createElement('cs:systemstatus');
95         $prop->setAttribute('type', $type);
96
97         $node->appendChild($prop);
98
99     }
100
101     /**
102      * This method serializes the entire notification, as it is used in the
103      * response body.
104      *
105      * @param Sabre_DAV_Server $server
106      * @param DOMElement $node
107      * @return void
108      */
109     public function serializeBody(Sabre_DAV_Server $server, \DOMElement $node) {
110
111         switch($this->type) {
112             case self::TYPE_LOW :
113                 $type = 'low';
114                 break;
115             case self::TYPE_MEDIUM :
116                 $type = 'medium';
117                 break;
118             default :
119             case self::TYPE_HIGH :
120                 $type = 'high';
121                 break;
122         }
123
124         $prop = $node->ownerDocument->createElement('cs:systemstatus');
125         $prop->setAttribute('type', $type);
126
127         if ($this->description) {
128             $text = $node->ownerDocument->createTextNode($this->description);
129             $desc = $node->ownerDocument->createElement('cs:description');
130             $desc->appendChild($text);
131             $prop->appendChild($desc);
132         }
133         if ($this->href) {
134             $text = $node->ownerDocument->createTextNode($this->href);
135             $href = $node->ownerDocument->createElement('d:href');
136             $href->appendChild($text);
137             $prop->appendChild($href);
138         }
139
140         $node->appendChild($prop);
141
142     }
143
144     /**
145      * Returns a unique id for this notification
146      *
147      * This is just the base url. This should generally be some kind of unique
148      * id.
149      *
150      * @return string
151      */
152     public function getId() {
153
154         return $this->id;
155
156     }
157
158 }