1<?php
2
3namespace Sabre\CalDAV\Notifications;
4
5use Sabre\DAV;
6use Sabre\CalDAV;
7use Sabre\CalDAV\Xml\Notification\NotificationInterface;
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) 2007-2015 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    /**
24     * The notification backend
25     *
26     * @var Sabre\CalDAV\Backend\NotificationSupport
27     */
28    protected $caldavBackend;
29
30    /**
31     * The actual notification
32     *
33     * @var Sabre\CalDAV\Notifications\INotificationType
34     */
35    protected $notification;
36
37    /**
38     * Owner principal of the notification
39     *
40     * @var string
41     */
42    protected $principalUri;
43
44    /**
45     * Constructor
46     *
47     * @param CalDAV\Backend\NotificationSupport $caldavBackend
48     * @param string $principalUri
49     * @param NotificationInterface $notification
50     */
51    function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification) {
52
53        $this->caldavBackend = $caldavBackend;
54        $this->principalUri = $principalUri;
55        $this->notification = $notification;
56
57    }
58
59    /**
60     * Returns the path name for this notification
61     *
62     * @return id
63     */
64    function getName() {
65
66        return $this->notification->getId() . '.xml';
67
68    }
69
70    /**
71     * Returns the etag for the notification.
72     *
73     * The etag must be surrounded by litteral double-quotes.
74     *
75     * @return string
76     */
77    function getETag() {
78
79        return $this->notification->getETag();
80
81    }
82
83    /**
84     * This method must return an xml element, using the
85     * Sabre\CalDAV\Notifications\INotificationType classes.
86     *
87     * @return INotificationType
88     */
89    function getNotificationType() {
90
91        return $this->notification;
92
93    }
94
95    /**
96     * Deletes this notification
97     *
98     * @return void
99     */
100    function delete() {
101
102        $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
103
104    }
105
106    /**
107     * Returns the owner principal
108     *
109     * This must be a url to a principal, or null if there's no owner
110     *
111     * @return string|null
112     */
113    function getOwner() {
114
115        return $this->principalUri;
116
117    }
118
119    /**
120     * Returns a group principal
121     *
122     * This must be a url to a principal, or null if there's no owner
123     *
124     * @return string|null
125     */
126    function getGroup() {
127
128        return null;
129
130    }
131
132    /**
133     * Returns a list of ACE's for this node.
134     *
135     * Each ACE has the following properties:
136     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
137     *     currently the only supported privileges
138     *   * 'principal', a url to the principal who owns the node
139     *   * 'protected' (optional), indicating that this ACE is not allowed to
140     *      be updated.
141     *
142     * @return array
143     */
144    function getACL() {
145
146        return [
147            [
148                'principal' => $this->getOwner(),
149                'privilege' => '{DAV:}read',
150                'protected' => true,
151            ],
152            [
153                'principal' => $this->getOwner(),
154                'privilege' => '{DAV:}write',
155                'protected' => true,
156            ]
157        ];
158
159    }
160
161    /**
162     * Updates the ACL
163     *
164     * This method will receive a list of new ACE's as an array argument.
165     *
166     * @param array $acl
167     * @return void
168     */
169    function setACL(array $acl) {
170
171        throw new DAV\Exception\NotImplemented('Updating ACLs is not implemented here');
172
173    }
174
175    /**
176     * Returns the list of supported privileges for this node.
177     *
178     * The returned data structure is a list of nested privileges.
179     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
180     * standard structure.
181     *
182     * If null is returned from this method, the default privilege set is used,
183     * which is fine for most common usecases.
184     *
185     * @return array|null
186     */
187    function getSupportedPrivilegeSet() {
188
189        return null;
190
191    }
192
193}
194