1<?php
2
3namespace Sabre\CalDAV\Notifications;
4
5use Sabre\CalDAV;
6use Sabre\CalDAV\Xml\Notification\NotificationInterface;
7use Sabre\DAV;
8use Sabre\DAVACL;
9
10/**
11 * This node represents a single notification.
12 *
13 * The signature is mostly identical to that of Sabre\DAV\IFile, but the get() method
14 * MUST return an xml document that matches the requirements of the
15 * 'caldav-notifications.txt' spec.
16 *
17 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
18 * @author Evert Pot (http://evertpot.com/)
19 * @license http://sabre.io/license/ Modified BSD License
20 */
21class Node extends DAV\File implements INode, DAVACL\IACL {
22
23    use DAVACL\ACLTrait;
24
25    /**
26     * The notification backend
27     *
28     * @var CalDAV\Backend\NotificationSupport
29     */
30    protected $caldavBackend;
31
32    /**
33     * The actual notification
34     *
35     * @var NotificationInterface
36     */
37    protected $notification;
38
39    /**
40     * Owner principal of the notification
41     *
42     * @var string
43     */
44    protected $principalUri;
45
46    /**
47     * Constructor
48     *
49     * @param CalDAV\Backend\NotificationSupport $caldavBackend
50     * @param string $principalUri
51     * @param NotificationInterface $notification
52     */
53    function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification) {
54
55        $this->caldavBackend = $caldavBackend;
56        $this->principalUri = $principalUri;
57        $this->notification = $notification;
58
59    }
60
61    /**
62     * Returns the path name for this notification
63     *
64     * @return string
65     */
66    function getName() {
67
68        return $this->notification->getId() . '.xml';
69
70    }
71
72    /**
73     * Returns the etag for the notification.
74     *
75     * The etag must be surrounded by litteral double-quotes.
76     *
77     * @return string
78     */
79    function getETag() {
80
81        return $this->notification->getETag();
82
83    }
84
85    /**
86     * This method must return an xml element, using the
87     * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
88     *
89     * @return NotificationInterface
90     */
91    function getNotificationType() {
92
93        return $this->notification;
94
95    }
96
97    /**
98     * Deletes this notification
99     *
100     * @return void
101     */
102    function delete() {
103
104        $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
105
106    }
107
108    /**
109     * Returns the owner principal
110     *
111     * This must be a url to a principal, or null if there's no owner
112     *
113     * @return string|null
114     */
115    function getOwner() {
116
117        return $this->principalUri;
118
119    }
120
121}
122