1<?php
2
3namespace Sabre\CalDAV\Notifications;
4
5use Sabre\DAV;
6use Sabre\CalDAV;
7use Sabre\DAVACL;
8
9/**
10 * This node represents a list of notifications.
11 *
12 * It provides no additional functionality, but you must implement this
13 * interface to allow the Notifications plugin to mark the collection
14 * as a notifications collection.
15 *
16 * This collection should only return Sabre\CalDAV\Notifications\INode nodes as
17 * its children.
18 *
19 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
20 * @author Evert Pot (http://evertpot.com/)
21 * @license http://sabre.io/license/ Modified BSD License
22 */
23class Collection extends DAV\Collection implements ICollection, DAVACL\IACL {
24
25    /**
26     * The notification backend
27     *
28     * @var Sabre\CalDAV\Backend\NotificationSupport
29     */
30    protected $caldavBackend;
31
32    /**
33     * Principal uri
34     *
35     * @var string
36     */
37    protected $principalUri;
38
39    /**
40     * Constructor
41     *
42     * @param CalDAV\Backend\NotificationSupport $caldavBackend
43     * @param string $principalUri
44     */
45    function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri) {
46
47        $this->caldavBackend = $caldavBackend;
48        $this->principalUri = $principalUri;
49
50    }
51
52    /**
53     * Returns all notifications for a principal
54     *
55     * @return array
56     */
57    function getChildren() {
58
59        $children = [];
60        $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);
61
62        foreach ($notifications as $notification) {
63
64            $children[] = new Node(
65                $this->caldavBackend,
66                $this->principalUri,
67                $notification
68            );
69        }
70
71        return $children;
72
73    }
74
75    /**
76     * Returns the name of this object
77     *
78     * @return string
79     */
80    function getName() {
81
82        return 'notifications';
83
84    }
85
86    /**
87     * Returns the owner principal
88     *
89     * This must be a url to a principal, or null if there's no owner
90     *
91     * @return string|null
92     */
93    function getOwner() {
94
95        return $this->principalUri;
96
97    }
98
99    /**
100     * Returns a group principal
101     *
102     * This must be a url to a principal, or null if there's no owner
103     *
104     * @return string|null
105     */
106    function getGroup() {
107
108        return null;
109
110    }
111
112    /**
113     * Returns a list of ACE's for this node.
114     *
115     * Each ACE has the following properties:
116     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
117     *     currently the only supported privileges
118     *   * 'principal', a url to the principal who owns the node
119     *   * 'protected' (optional), indicating that this ACE is not allowed to
120     *      be updated.
121     *
122     * @return array
123     */
124    function getACL() {
125
126        return [
127            [
128                'principal' => $this->getOwner(),
129                'privilege' => '{DAV:}read',
130                'protected' => true,
131            ],
132            [
133                'principal' => $this->getOwner(),
134                'privilege' => '{DAV:}write',
135                'protected' => true,
136            ]
137        ];
138
139    }
140
141    /**
142     * Updates the ACL
143     *
144     * This method will receive a list of new ACE's as an array argument.
145     *
146     * @param array $acl
147     * @return void
148     */
149    function setACL(array $acl) {
150
151        throw new DAV\Exception\NotImplemented('Updating ACLs is not implemented here');
152
153    }
154
155    /**
156     * Returns the list of supported privileges for this node.
157     *
158     * The returned data structure is a list of nested privileges.
159     * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
160     * standard structure.
161     *
162     * If null is returned from this method, the default privilege set is used,
163     * which is fine for most common usecases.
164     *
165     * @return array|null
166     */
167    function getSupportedPrivilegeSet() {
168
169        return null;
170
171    }
172
173}
174