diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2012-10-13 22:03:44 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2012-10-13 22:04:22 +0200 |
commit | 183cc22501b75ab8819971f70b88dbc010026ac1 (patch) | |
tree | 878db72be46fe5394f8615c2bcf579d9e943d76b /3rdparty/Sabre/CalDAV/Notifications | |
parent | 5713dcfd11f6d0f57b6302bedeb22c18df5d73bb (diff) | |
download | nextcloud-server-183cc22501b75ab8819971f70b88dbc010026ac1.tar.gz nextcloud-server-183cc22501b75ab8819971f70b88dbc010026ac1.zip |
Update SabreDAV to 1.7.1
Diffstat (limited to '3rdparty/Sabre/CalDAV/Notifications')
8 files changed, 1131 insertions, 0 deletions
diff --git a/3rdparty/Sabre/CalDAV/Notifications/Collection.php b/3rdparty/Sabre/CalDAV/Notifications/Collection.php new file mode 100755 index 00000000000..83b6c9301dc --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/Collection.php @@ -0,0 +1,169 @@ +<?php + +/** + * This node represents a list of notifications. + * + * It provides no additional functionality, but you must implement this + * interface to allow the Notifications plugin to mark the collection + * as a notifications collection. + * + * This collection should only return Sabre_CalDAV_Notifications_INode nodes as + * its children. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_CalDAV_Notifications_Collection extends Sabre_DAV_Collection implements Sabre_CalDAV_Notifications_ICollection, Sabre_DAVACL_IACL { + + /** + * The notification backend + * + * @var Sabre_CalDAV_Backend_NotificationSupport + */ + protected $caldavBackend; + + /** + * Principal uri + * + * @var string + */ + protected $principalUri; + + /** + * Constructor + * + * @param Sabre_CalDAV_Backend_NotificationSupport $caldavBackend + * @param string $principalUri + */ + public function __construct(Sabre_CalDAV_Backend_NotificationSupport $caldavBackend, $principalUri) { + + $this->caldavBackend = $caldavBackend; + $this->principalUri = $principalUri; + + } + + /** + * Returns all notifications for a principal + * + * @return array + */ + public function getChildren() { + + $children = array(); + $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri); + + foreach($notifications as $notification) { + + $children[] = new Sabre_CalDAV_Notifications_Node( + $this->caldavBackend, + $this->principalUri, + $notification + ); + } + + return $children; + + } + + /** + * Returns the name of this object + * + * @return string + */ + public function getName() { + + return 'notifications'; + + } + + /** + * Returns the owner principal + * + * This must be a url to a principal, or null if there's no owner + * + * @return string|null + */ + public function getOwner() { + + return $this->principalUri; + + } + + /** + * Returns a group principal + * + * This must be a url to a principal, or null if there's no owner + * + * @return string|null + */ + public function getGroup() { + + return null; + + } + + /** + * Returns a list of ACE's for this node. + * + * Each ACE has the following properties: + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are + * currently the only supported privileges + * * 'principal', a url to the principal who owns the node + * * 'protected' (optional), indicating that this ACE is not allowed to + * be updated. + * + * @return array + */ + public function getACL() { + + return array( + array( + 'principal' => $this->getOwner(), + 'privilege' => '{DAV:}read', + 'protected' => true, + ), + array( + 'principal' => $this->getOwner(), + 'privilege' => '{DAV:}write', + 'protected' => true, + ) + ); + + } + + /** + * Updates the ACL + * + * This method will receive a list of new ACE's as an array argument. + * + * @param array $acl + * @return void + */ + public function setACL(array $acl) { + + throw new Sabre_DAV_Exception_NotImplemented('Updating ACLs is not implemented here'); + + } + + /** + * Returns the list of supported privileges for this node. + * + * The returned data structure is a list of nested privileges. + * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple + * standard structure. + * + * If null is returned from this method, the default privilege set is used, + * which is fine for most common usecases. + * + * @return array|null + */ + public function getSupportedPrivilegeSet() { + + return null; + + } + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/ICollection.php b/3rdparty/Sabre/CalDAV/Notifications/ICollection.php new file mode 100755 index 00000000000..eb873af3f92 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/ICollection.php @@ -0,0 +1,22 @@ +<?php + +/** + * This node represents a list of notifications. + * + * It provides no additional functionality, but you must implement this + * interface to allow the Notifications plugin to mark the collection + * as a notifications collection. + * + * This collection should only return Sabre_CalDAV_Notifications_INode nodes as + * its children. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +interface Sabre_CalDAV_Notifications_ICollection extends Sabre_DAV_ICollection { + + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/INode.php b/3rdparty/Sabre/CalDAV/Notifications/INode.php new file mode 100755 index 00000000000..84721de5ab7 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/INode.php @@ -0,0 +1,38 @@ +<?php + +/** + * This node represents a single notification. + * + * The signature is mostly identical to that of Sabre_DAV_IFile, but the get() method + * MUST return an xml document that matches the requirements of the + * 'caldav-notifications.txt' spec. + * + * For a complete example, check out the Notification class, which contains + * some helper functions. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +interface Sabre_CalDAV_Notifications_INode { + + /** + * This method must return an xml element, using the + * Sabre_CalDAV_Notifications_INotificationType classes. + * + * @return Sabre_DAVNotification_INotificationType + */ + function getNotificationType(); + + /** + * Returns the etag for the notification. + * + * The etag must be surrounded by litteral double-quotes. + * + * @return string + */ + function getETag(); + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/INotificationType.php b/3rdparty/Sabre/CalDAV/Notifications/INotificationType.php new file mode 100755 index 00000000000..02a65a01fa3 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/INotificationType.php @@ -0,0 +1,43 @@ +<?php + +/** + * This interface reflects a single notification type. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +interface Sabre_CalDAV_Notifications_INotificationType extends Sabre_DAV_PropertyInterface { + + /** + * This method serializes the entire notification, as it is used in the + * response body. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + function serializeBody(Sabre_DAV_Server $server, \DOMElement $node); + + /** + * Returns a unique id for this notification + * + * This is just the base url. This should generally be some kind of unique + * id. + * + * @return string + */ + function getId(); + + /** + * Returns the ETag for this notification. + * + * The ETag must be surrounded by literal double-quotes. + * + * @return string + */ + function getETag(); + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/Node.php b/3rdparty/Sabre/CalDAV/Notifications/Node.php new file mode 100755 index 00000000000..8021a75debf --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/Node.php @@ -0,0 +1,188 @@ +<?php + +/** + * This node represents a single notification. + * + * The signature is mostly identical to that of Sabre_DAV_IFile, but the get() method + * MUST return an xml document that matches the requirements of the + * 'caldav-notifications.txt' spec. + + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_CalDAV_Notifications_Node extends Sabre_DAV_File implements Sabre_CalDAV_Notifications_INode, Sabre_DAVACL_IACL { + + /** + * The notification backend + * + * @var Sabre_CalDAV_Backend_NotificationSupport + */ + protected $caldavBackend; + + /** + * The actual notification + * + * @var Sabre_CalDAV_Notifications_INotificationType + */ + protected $notification; + + /** + * Owner principal of the notification + * + * @var string + */ + protected $principalUri; + + /** + * Constructor + * + * @param Sabre_CalDAV_Backend_NotificationSupport $caldavBackend + * @param string $principalUri + * @param Sabre_CalDAV_Notifications_INotificationType $notification + */ + public function __construct(Sabre_CalDAV_Backend_NotificationSupport $caldavBackend, $principalUri, Sabre_CalDAV_Notifications_INotificationType $notification) { + + $this->caldavBackend = $caldavBackend; + $this->principalUri = $principalUri; + $this->notification = $notification; + + } + + /** + * Returns the path name for this notification + * + * @return id + */ + public function getName() { + + return $this->notification->getId() . '.xml'; + + } + + /** + * Returns the etag for the notification. + * + * The etag must be surrounded by litteral double-quotes. + * + * @return string + */ + public function getETag() { + + return $this->notification->getETag(); + + } + + /** + * This method must return an xml element, using the + * Sabre_CalDAV_Notifications_INotificationType classes. + * + * @return Sabre_DAVNotification_INotificationType + */ + public function getNotificationType() { + + return $this->notification; + + } + + /** + * Deletes this notification + * + * @return void + */ + public function delete() { + + $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification); + + } + + /** + * Returns the owner principal + * + * This must be a url to a principal, or null if there's no owner + * + * @return string|null + */ + public function getOwner() { + + return $this->principalUri; + + } + + /** + * Returns a group principal + * + * This must be a url to a principal, or null if there's no owner + * + * @return string|null + */ + public function getGroup() { + + return null; + + } + + /** + * Returns a list of ACE's for this node. + * + * Each ACE has the following properties: + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are + * currently the only supported privileges + * * 'principal', a url to the principal who owns the node + * * 'protected' (optional), indicating that this ACE is not allowed to + * be updated. + * + * @return array + */ + public function getACL() { + + return array( + array( + 'principal' => $this->getOwner(), + 'privilege' => '{DAV:}read', + 'protected' => true, + ), + array( + 'principal' => $this->getOwner(), + 'privilege' => '{DAV:}write', + 'protected' => true, + ) + ); + + } + + /** + * Updates the ACL + * + * This method will receive a list of new ACE's as an array argument. + * + * @param array $acl + * @return void + */ + public function setACL(array $acl) { + + throw new Sabre_DAV_Exception_NotImplemented('Updating ACLs is not implemented here'); + + } + + /** + * Returns the list of supported privileges for this node. + * + * The returned data structure is a list of nested privileges. + * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple + * standard structure. + * + * If null is returned from this method, the default privilege set is used, + * which is fine for most common usecases. + * + * @return array|null + */ + public function getSupportedPrivilegeSet() { + + return null; + + } + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/Notification/Invite.php b/3rdparty/Sabre/CalDAV/Notifications/Notification/Invite.php new file mode 100755 index 00000000000..a6b36203f34 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/Notification/Invite.php @@ -0,0 +1,276 @@ +<?php + +use Sabre_CalDAV_SharingPlugin as SharingPlugin; + +/** + * This class represents the cs:invite-notification notification element. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_CalDAV_Notifications_Notification_Invite extends Sabre_DAV_Property implements Sabre_CalDAV_Notifications_INotificationType { + + /** + * A unique id for the message + * + * @var string + */ + protected $id; + + /** + * Timestamp of the notification + * + * @var DateTime + */ + protected $dtStamp; + + /** + * A url to the recipient of the notification. This can be an email + * address (mailto:), or a principal url. + * + * @var string + */ + protected $href; + + /** + * The type of message, see the SharingPlugin::STATUS_* constants. + * + * @var int + */ + protected $type; + + /** + * True if access to a calendar is read-only. + * + * @var bool + */ + protected $readOnly; + + /** + * A url to the shared calendar. + * + * @var string + */ + protected $hostUrl; + + /** + * Url to the sharer of the calendar + * + * @var string + */ + protected $organizer; + + /** + * The name of the sharer. + * + * @var string + */ + protected $commonName; + + /** + * A description of the share request + * + * @var string + */ + protected $summary; + + /** + * The Etag for the notification + * + * @var string + */ + protected $etag; + + /** + * The list of supported components + * + * @var Sabre_CalDAV_Property_SupportedCalendarComponentSet + */ + protected $supportedComponents; + + /** + * Creates the Invite notification. + * + * This constructor receives an array with the following elements: + * + * * id - A unique id + * * etag - The etag + * * dtStamp - A DateTime object with a timestamp for the notification. + * * type - The type of notification, see SharingPlugin::STATUS_* + * constants for details. + * * readOnly - This must be set to true, if this is an invite for + * read-only access to a calendar. + * * hostUrl - A url to the shared calendar. + * * organizer - Url to the sharer principal. + * * commonName - The real name of the sharer (optional). + * * summary - Description of the share, can be the same as the + * calendar, but may also be modified (optional). + * * supportedComponents - An instance of + * Sabre_CalDAV_Property_SupportedCalendarComponentSet. + * This allows the client to determine which components + * will be supported in the shared calendar. This is + * also optional. + * + * @param array $values All the options + */ + public function __construct(array $values) { + + $required = array( + 'id', + 'etag', + 'href', + 'dtStamp', + 'type', + 'readOnly', + 'hostUrl', + 'organizer', + ); + foreach($required as $item) { + if (!isset($values[$item])) { + throw new InvalidArgumentException($item . ' is a required constructor option'); + } + } + + foreach($values as $key=>$value) { + if (!property_exists($this, $key)) { + throw new InvalidArgumentException('Unknown option: ' . $key); + } + $this->$key = $value; + } + + } + + /** + * Serializes the notification as a single property. + * + * You should usually just encode the single top-level element of the + * notification. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serialize(Sabre_DAV_Server $server, \DOMElement $node) { + + $prop = $node->ownerDocument->createElement('cs:invite-notification'); + $node->appendChild($prop); + + } + + /** + * This method serializes the entire notification, as it is used in the + * response body. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serializeBody(Sabre_DAV_Server $server, \DOMElement $node) { + + $doc = $node->ownerDocument; + + $dt = $doc->createElement('cs:dtstamp'); + $this->dtStamp->setTimezone(new \DateTimezone('GMT')); + $dt->appendChild($doc->createTextNode($this->dtStamp->format('Ymd\\THis\\Z'))); + $node->appendChild($dt); + + $prop = $doc->createElement('cs:invite-notification'); + $node->appendChild($prop); + + $uid = $doc->createElement('cs:uid'); + $uid->appendChild( $doc->createTextNode($this->id) ); + $prop->appendChild($uid); + + $href = $doc->createElement('d:href'); + $href->appendChild( $doc->createTextNode( $this->href ) ); + $prop->appendChild($href); + + $nodeName = null; + switch($this->type) { + + case SharingPlugin::STATUS_ACCEPTED : + $nodeName = 'cs:invite-accepted'; + break; + case SharingPlugin::STATUS_DECLINED : + $nodeName = 'cs:invite-declined'; + break; + case SharingPlugin::STATUS_DELETED : + $nodeName = 'cs:invite-deleted'; + break; + case SharingPlugin::STATUS_NORESPONSE : + $nodeName = 'cs:invite-noresponse'; + break; + + } + $prop->appendChild( + $doc->createElement($nodeName) + ); + $hostHref = $doc->createElement('d:href', $server->getBaseUri() . $this->hostUrl); + $hostUrl = $doc->createElement('cs:hosturl'); + $hostUrl->appendChild($hostHref); + $prop->appendChild($hostUrl); + + $access = $doc->createElement('cs:access'); + if ($this->readOnly) { + $access->appendChild($doc->createElement('cs:read')); + } else { + $access->appendChild($doc->createElement('cs:read-write')); + } + $prop->appendChild($access); + + $organizerHref = $doc->createElement('d:href', $server->getBaseUri() . $this->organizer); + $organizerUrl = $doc->createElement('cs:organizer'); + if ($this->commonName) { + $commonName = $doc->createElement('cs:common-name'); + $commonName->appendChild($doc->createTextNode($this->commonName)); + $organizerUrl->appendChild($commonName); + } + $organizerUrl->appendChild($organizerHref); + $prop->appendChild($organizerUrl); + + if ($this->summary) { + $summary = $doc->createElement('cs:summary'); + $summary->appendChild($doc->createTextNode($this->summary)); + $prop->appendChild($summary); + } + if ($this->supportedComponents) { + + $xcomp = $doc->createElement('cal:supported-calendar-component-set'); + $this->supportedComponents->serialize($server, $xcomp); + $prop->appendChild($xcomp); + + } + + } + + /** + * Returns a unique id for this notification + * + * This is just the base url. This should generally be some kind of unique + * id. + * + * @return string + */ + public function getId() { + + return $this->id; + + } + + /** + * Returns the ETag for this notification. + * + * The ETag must be surrounded by literal double-quotes. + * + * @return string + */ + public function getETag() { + + return $this->etag; + + } + +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/Notification/InviteReply.php b/3rdparty/Sabre/CalDAV/Notifications/Notification/InviteReply.php new file mode 100755 index 00000000000..e935aa5aa11 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/Notification/InviteReply.php @@ -0,0 +1,216 @@ +<?php + +use Sabre_CalDAV_SharingPlugin as SharingPlugin; + +/** + * This class represents the cs:invite-reply notification element. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_CalDAV_Notifications_Notification_InviteReply extends Sabre_DAV_Property implements Sabre_CalDAV_Notifications_INotificationType { + + /** + * A unique id for the message + * + * @var string + */ + protected $id; + + /** + * Timestamp of the notification + * + * @var DateTime + */ + protected $dtStamp; + + /** + * The unique id of the notification this was a reply to. + * + * @var string + */ + protected $inReplyTo; + + /** + * A url to the recipient of the original (!) notification. + * + * @var string + */ + protected $href; + + /** + * The type of message, see the SharingPlugin::STATUS_ constants. + * + * @var int + */ + protected $type; + + /** + * A url to the shared calendar. + * + * @var string + */ + protected $hostUrl; + + /** + * A description of the share request + * + * @var string + */ + protected $summary; + + /** + * Notification Etag + * + * @var string + */ + protected $etag; + + /** + * Creates the Invite Reply Notification. + * + * This constructor receives an array with the following elements: + * + * * id - A unique id + * * etag - The etag + * * dtStamp - A DateTime object with a timestamp for the notification. + * * inReplyTo - This should refer to the 'id' of the notification + * this is a reply to. + * * type - The type of notification, see SharingPlugin::STATUS_* + * constants for details. + * * hostUrl - A url to the shared calendar. + * * summary - Description of the share, can be the same as the + * calendar, but may also be modified (optional). + */ + public function __construct(array $values) { + + $required = array( + 'id', + 'etag', + 'href', + 'dtStamp', + 'inReplyTo', + 'type', + 'hostUrl', + ); + foreach($required as $item) { + if (!isset($values[$item])) { + throw new InvalidArgumentException($item . ' is a required constructor option'); + } + } + + foreach($values as $key=>$value) { + if (!property_exists($this, $key)) { + throw new InvalidArgumentException('Unknown option: ' . $key); + } + $this->$key = $value; + } + + } + + /** + * Serializes the notification as a single property. + * + * You should usually just encode the single top-level element of the + * notification. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serialize(Sabre_DAV_Server $server, \DOMElement $node) { + + $prop = $node->ownerDocument->createElement('cs:invite-reply'); + $node->appendChild($prop); + + } + + /** + * This method serializes the entire notification, as it is used in the + * response body. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serializeBody(Sabre_DAV_Server $server, \DOMElement $node) { + + $doc = $node->ownerDocument; + + $dt = $doc->createElement('cs:dtstamp'); + $this->dtStamp->setTimezone(new \DateTimezone('GMT')); + $dt->appendChild($doc->createTextNode($this->dtStamp->format('Ymd\\THis\\Z'))); + $node->appendChild($dt); + + $prop = $doc->createElement('cs:invite-reply'); + $node->appendChild($prop); + + $uid = $doc->createElement('cs:uid'); + $uid->appendChild($doc->createTextNode($this->id)); + $prop->appendChild($uid); + + $inReplyTo = $doc->createElement('cs:in-reply-to'); + $inReplyTo->appendChild( $doc->createTextNode($this->inReplyTo) ); + $prop->appendChild($inReplyTo); + + $href = $doc->createElement('d:href'); + $href->appendChild( $doc->createTextNode($this->href) ); + $prop->appendChild($href); + + $nodeName = null; + switch($this->type) { + + case SharingPlugin::STATUS_ACCEPTED : + $nodeName = 'cs:invite-accepted'; + break; + case SharingPlugin::STATUS_DECLINED : + $nodeName = 'cs:invite-declined'; + break; + + } + $prop->appendChild( + $doc->createElement($nodeName) + ); + $hostHref = $doc->createElement('d:href', $server->getBaseUri() . $this->hostUrl); + $hostUrl = $doc->createElement('cs:hosturl'); + $hostUrl->appendChild($hostHref); + $prop->appendChild($hostUrl); + + if ($this->summary) { + $summary = $doc->createElement('cs:summary'); + $summary->appendChild($doc->createTextNode($this->summary)); + $prop->appendChild($summary); + } + + } + + /** + * Returns a unique id for this notification + * + * This is just the base url. This should generally be some kind of unique + * id. + * + * @return string + */ + public function getId() { + + return $this->id; + + } + + /** + * Returns the ETag for this notification. + * + * The ETag must be surrounded by literal double-quotes. + * + * @return string + */ + public function getETag() { + + return $this->etag; + + } +} diff --git a/3rdparty/Sabre/CalDAV/Notifications/Notification/SystemStatus.php b/3rdparty/Sabre/CalDAV/Notifications/Notification/SystemStatus.php new file mode 100755 index 00000000000..f09ed3525f5 --- /dev/null +++ b/3rdparty/Sabre/CalDAV/Notifications/Notification/SystemStatus.php @@ -0,0 +1,179 @@ +<?php + +/** + * SystemStatus notification + * + * This notification can be used to indicate to the user that the system is + * down. + * + * @package Sabre + * @subpackage CalDAV + * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_CalDAV_Notifications_Notification_SystemStatus extends Sabre_DAV_Property implements Sabre_CalDAV_Notifications_INotificationType { + + const TYPE_LOW = 1; + const TYPE_MEDIUM = 2; + const TYPE_HIGH = 3; + + /** + * A unique id + * + * @var string + */ + protected $id; + + /** + * The type of alert. This should be one of the TYPE_ constants. + * + * @var int + */ + protected $type; + + /** + * A human-readable description of the problem. + * + * @var string + */ + protected $description; + + /** + * A url to a website with more information for the user. + * + * @var string + */ + protected $href; + + /** + * Notification Etag + * + * @var string + */ + protected $etag; + + /** + * Creates the notification. + * + * Some kind of unique id should be provided. This is used to generate a + * url. + * + * @param string $id + * @param string $etag + * @param int $type + * @param string $description + * @param string $href + */ + public function __construct($id, $etag, $type = self::TYPE_HIGH, $description = null, $href = null) { + + $this->id = $id; + $this->type = $type; + $this->description = $description; + $this->href = $href; + $this->etag = $etag; + + } + + /** + * Serializes the notification as a single property. + * + * You should usually just encode the single top-level element of the + * notification. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serialize(Sabre_DAV_Server $server, \DOMElement $node) { + + switch($this->type) { + case self::TYPE_LOW : + $type = 'low'; + break; + case self::TYPE_MEDIUM : + $type = 'medium'; + break; + default : + case self::TYPE_HIGH : + $type = 'high'; + break; + } + + $prop = $node->ownerDocument->createElement('cs:systemstatus'); + $prop->setAttribute('type', $type); + + $node->appendChild($prop); + + } + + /** + * This method serializes the entire notification, as it is used in the + * response body. + * + * @param Sabre_DAV_Server $server + * @param DOMElement $node + * @return void + */ + public function serializeBody(Sabre_DAV_Server $server, \DOMElement $node) { + + switch($this->type) { + case self::TYPE_LOW : + $type = 'low'; + break; + case self::TYPE_MEDIUM : + $type = 'medium'; + break; + default : + case self::TYPE_HIGH : + $type = 'high'; + break; + } + + $prop = $node->ownerDocument->createElement('cs:systemstatus'); + $prop->setAttribute('type', $type); + + if ($this->description) { + $text = $node->ownerDocument->createTextNode($this->description); + $desc = $node->ownerDocument->createElement('cs:description'); + $desc->appendChild($text); + $prop->appendChild($desc); + } + if ($this->href) { + $text = $node->ownerDocument->createTextNode($this->href); + $href = $node->ownerDocument->createElement('d:href'); + $href->appendChild($text); + $prop->appendChild($href); + } + + $node->appendChild($prop); + + } + + /** + * Returns a unique id for this notification + * + * This is just the base url. This should generally be some kind of unique + * id. + * + * @return string + */ + public function getId() { + + return $this->id; + + } + + /* + * Returns the ETag for this notification. + * + * The ETag must be surrounded by literal double-quotes. + * + * @return string + */ + public function getETag() { + + return $this->etag; + + } +} |