xref: /plugin/davcal/vendor/sabre/dav/lib/CalDAV/Subscriptions/Subscription.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV\Subscriptions;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV\Collection;
6*a1a3b679SAndreas Boehleruse Sabre\DAV\Xml\Property\Href;
7*a1a3b679SAndreas Boehleruse Sabre\DAV\PropPatch;
8*a1a3b679SAndreas Boehleruse Sabre\DAV\Exception\MethodNotAllowed;
9*a1a3b679SAndreas Boehleruse Sabre\DAVACL\IACL;
10*a1a3b679SAndreas Boehleruse Sabre\CalDAV\Backend\SubscriptionSupport;
11*a1a3b679SAndreas Boehler
12*a1a3b679SAndreas Boehler/**
13*a1a3b679SAndreas Boehler * Subscription Node
14*a1a3b679SAndreas Boehler *
15*a1a3b679SAndreas Boehler * This node represents a subscription.
16*a1a3b679SAndreas Boehler *
17*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
18*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
19*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
20*a1a3b679SAndreas Boehler */
21*a1a3b679SAndreas Boehlerclass Subscription extends Collection implements ISubscription, IACL {
22*a1a3b679SAndreas Boehler
23*a1a3b679SAndreas Boehler    /**
24*a1a3b679SAndreas Boehler     * caldavBackend
25*a1a3b679SAndreas Boehler     *
26*a1a3b679SAndreas Boehler     * @var SupportsSubscriptions
27*a1a3b679SAndreas Boehler     */
28*a1a3b679SAndreas Boehler    protected $caldavBackend;
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler    /**
31*a1a3b679SAndreas Boehler     * subscriptionInfo
32*a1a3b679SAndreas Boehler     *
33*a1a3b679SAndreas Boehler     * @var array
34*a1a3b679SAndreas Boehler     */
35*a1a3b679SAndreas Boehler    protected $subscriptionInfo;
36*a1a3b679SAndreas Boehler
37*a1a3b679SAndreas Boehler    /**
38*a1a3b679SAndreas Boehler     * Constructor
39*a1a3b679SAndreas Boehler     *
40*a1a3b679SAndreas Boehler     * @param SubscriptionSupport $caldavBackend
41*a1a3b679SAndreas Boehler     * @param array $calendarInfo
42*a1a3b679SAndreas Boehler     */
43*a1a3b679SAndreas Boehler    function __construct(SubscriptionSupport $caldavBackend, array $subscriptionInfo) {
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler        $this->caldavBackend = $caldavBackend;
46*a1a3b679SAndreas Boehler        $this->subscriptionInfo = $subscriptionInfo;
47*a1a3b679SAndreas Boehler
48*a1a3b679SAndreas Boehler        $required = [
49*a1a3b679SAndreas Boehler            'id',
50*a1a3b679SAndreas Boehler            'uri',
51*a1a3b679SAndreas Boehler            'principaluri',
52*a1a3b679SAndreas Boehler            'source',
53*a1a3b679SAndreas Boehler            ];
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler        foreach ($required as $r) {
56*a1a3b679SAndreas Boehler            if (!isset($subscriptionInfo[$r])) {
57*a1a3b679SAndreas Boehler                throw new \InvalidArgumentException('The ' . $r . ' field is required when creating a subscription node');
58*a1a3b679SAndreas Boehler            }
59*a1a3b679SAndreas Boehler        }
60*a1a3b679SAndreas Boehler
61*a1a3b679SAndreas Boehler    }
62*a1a3b679SAndreas Boehler
63*a1a3b679SAndreas Boehler    /**
64*a1a3b679SAndreas Boehler     * Returns the name of the node.
65*a1a3b679SAndreas Boehler     *
66*a1a3b679SAndreas Boehler     * This is used to generate the url.
67*a1a3b679SAndreas Boehler     *
68*a1a3b679SAndreas Boehler     * @return string
69*a1a3b679SAndreas Boehler     */
70*a1a3b679SAndreas Boehler    function getName() {
71*a1a3b679SAndreas Boehler
72*a1a3b679SAndreas Boehler        return $this->subscriptionInfo['uri'];
73*a1a3b679SAndreas Boehler
74*a1a3b679SAndreas Boehler    }
75*a1a3b679SAndreas Boehler
76*a1a3b679SAndreas Boehler    /**
77*a1a3b679SAndreas Boehler     * Returns the last modification time
78*a1a3b679SAndreas Boehler     *
79*a1a3b679SAndreas Boehler     * @return int
80*a1a3b679SAndreas Boehler     */
81*a1a3b679SAndreas Boehler    function getLastModified() {
82*a1a3b679SAndreas Boehler
83*a1a3b679SAndreas Boehler        if (isset($this->subscriptionInfo['lastmodified'])) {
84*a1a3b679SAndreas Boehler            return $this->subscriptionInfo['lastmodified'];
85*a1a3b679SAndreas Boehler        }
86*a1a3b679SAndreas Boehler
87*a1a3b679SAndreas Boehler    }
88*a1a3b679SAndreas Boehler
89*a1a3b679SAndreas Boehler    /**
90*a1a3b679SAndreas Boehler     * Deletes the current node
91*a1a3b679SAndreas Boehler     *
92*a1a3b679SAndreas Boehler     * @return void
93*a1a3b679SAndreas Boehler     */
94*a1a3b679SAndreas Boehler    function delete() {
95*a1a3b679SAndreas Boehler
96*a1a3b679SAndreas Boehler        $this->caldavBackend->deleteSubscription(
97*a1a3b679SAndreas Boehler            $this->subscriptionInfo['id']
98*a1a3b679SAndreas Boehler        );
99*a1a3b679SAndreas Boehler
100*a1a3b679SAndreas Boehler    }
101*a1a3b679SAndreas Boehler
102*a1a3b679SAndreas Boehler    /**
103*a1a3b679SAndreas Boehler     * Returns an array with all the child nodes
104*a1a3b679SAndreas Boehler     *
105*a1a3b679SAndreas Boehler     * @return DAV\INode[]
106*a1a3b679SAndreas Boehler     */
107*a1a3b679SAndreas Boehler    function getChildren() {
108*a1a3b679SAndreas Boehler
109*a1a3b679SAndreas Boehler        return [];
110*a1a3b679SAndreas Boehler
111*a1a3b679SAndreas Boehler    }
112*a1a3b679SAndreas Boehler
113*a1a3b679SAndreas Boehler    /**
114*a1a3b679SAndreas Boehler     * Updates properties on this node.
115*a1a3b679SAndreas Boehler     *
116*a1a3b679SAndreas Boehler     * This method received a PropPatch object, which contains all the
117*a1a3b679SAndreas Boehler     * information about the update.
118*a1a3b679SAndreas Boehler     *
119*a1a3b679SAndreas Boehler     * To update specific properties, call the 'handle' method on this object.
120*a1a3b679SAndreas Boehler     * Read the PropPatch documentation for more information.
121*a1a3b679SAndreas Boehler     *
122*a1a3b679SAndreas Boehler     * @param PropPatch $propPatch
123*a1a3b679SAndreas Boehler     * @return void
124*a1a3b679SAndreas Boehler     */
125*a1a3b679SAndreas Boehler    function propPatch(PropPatch $propPatch) {
126*a1a3b679SAndreas Boehler
127*a1a3b679SAndreas Boehler        return $this->caldavBackend->updateSubscription(
128*a1a3b679SAndreas Boehler            $this->subscriptionInfo['id'],
129*a1a3b679SAndreas Boehler            $propPatch
130*a1a3b679SAndreas Boehler        );
131*a1a3b679SAndreas Boehler
132*a1a3b679SAndreas Boehler    }
133*a1a3b679SAndreas Boehler
134*a1a3b679SAndreas Boehler    /**
135*a1a3b679SAndreas Boehler     * Returns a list of properties for this nodes.
136*a1a3b679SAndreas Boehler     *
137*a1a3b679SAndreas Boehler     * The properties list is a list of propertynames the client requested,
138*a1a3b679SAndreas Boehler     * encoded in clark-notation {xmlnamespace}tagname.
139*a1a3b679SAndreas Boehler     *
140*a1a3b679SAndreas Boehler     * If the array is empty, it means 'all properties' were requested.
141*a1a3b679SAndreas Boehler     *
142*a1a3b679SAndreas Boehler     * Note that it's fine to liberally give properties back, instead of
143*a1a3b679SAndreas Boehler     * conforming to the list of requested properties.
144*a1a3b679SAndreas Boehler     * The Server class will filter out the extra.
145*a1a3b679SAndreas Boehler     *
146*a1a3b679SAndreas Boehler     * @param array $properties
147*a1a3b679SAndreas Boehler     * @return void
148*a1a3b679SAndreas Boehler     */
149*a1a3b679SAndreas Boehler    function getProperties($properties) {
150*a1a3b679SAndreas Boehler
151*a1a3b679SAndreas Boehler        $r = [];
152*a1a3b679SAndreas Boehler
153*a1a3b679SAndreas Boehler        foreach ($properties as $prop) {
154*a1a3b679SAndreas Boehler
155*a1a3b679SAndreas Boehler            switch ($prop) {
156*a1a3b679SAndreas Boehler                case '{http://calendarserver.org/ns/}source' :
157*a1a3b679SAndreas Boehler                    $r[$prop] = new Href($this->subscriptionInfo['source'], false);
158*a1a3b679SAndreas Boehler                    break;
159*a1a3b679SAndreas Boehler                default :
160*a1a3b679SAndreas Boehler                    if (array_key_exists($prop, $this->subscriptionInfo)) {
161*a1a3b679SAndreas Boehler                        $r[$prop] = $this->subscriptionInfo[$prop];
162*a1a3b679SAndreas Boehler                    }
163*a1a3b679SAndreas Boehler                    break;
164*a1a3b679SAndreas Boehler            }
165*a1a3b679SAndreas Boehler
166*a1a3b679SAndreas Boehler        }
167*a1a3b679SAndreas Boehler
168*a1a3b679SAndreas Boehler        return $r;
169*a1a3b679SAndreas Boehler
170*a1a3b679SAndreas Boehler    }
171*a1a3b679SAndreas Boehler
172*a1a3b679SAndreas Boehler    /**
173*a1a3b679SAndreas Boehler     * Returns the owner principal.
174*a1a3b679SAndreas Boehler     *
175*a1a3b679SAndreas Boehler     * This must be a url to a principal, or null if there's no owner
176*a1a3b679SAndreas Boehler     *
177*a1a3b679SAndreas Boehler     * @return string|null
178*a1a3b679SAndreas Boehler     */
179*a1a3b679SAndreas Boehler    function getOwner() {
180*a1a3b679SAndreas Boehler
181*a1a3b679SAndreas Boehler        return $this->subscriptionInfo['principaluri'];
182*a1a3b679SAndreas Boehler
183*a1a3b679SAndreas Boehler    }
184*a1a3b679SAndreas Boehler
185*a1a3b679SAndreas Boehler    /**
186*a1a3b679SAndreas Boehler     * Returns a group principal.
187*a1a3b679SAndreas Boehler     *
188*a1a3b679SAndreas Boehler     * This must be a url to a principal, or null if there's no owner
189*a1a3b679SAndreas Boehler     *
190*a1a3b679SAndreas Boehler     * @return string|null
191*a1a3b679SAndreas Boehler     */
192*a1a3b679SAndreas Boehler    function getGroup() {
193*a1a3b679SAndreas Boehler
194*a1a3b679SAndreas Boehler        return null;
195*a1a3b679SAndreas Boehler
196*a1a3b679SAndreas Boehler    }
197*a1a3b679SAndreas Boehler
198*a1a3b679SAndreas Boehler    /**
199*a1a3b679SAndreas Boehler     * Returns a list of ACE's for this node.
200*a1a3b679SAndreas Boehler     *
201*a1a3b679SAndreas Boehler     * Each ACE has the following properties:
202*a1a3b679SAndreas Boehler     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
203*a1a3b679SAndreas Boehler     *     currently the only supported privileges
204*a1a3b679SAndreas Boehler     *   * 'principal', a url to the principal who owns the node
205*a1a3b679SAndreas Boehler     *   * 'protected' (optional), indicating that this ACE is not allowed to
206*a1a3b679SAndreas Boehler     *      be updated.
207*a1a3b679SAndreas Boehler     *
208*a1a3b679SAndreas Boehler     * @return array
209*a1a3b679SAndreas Boehler     */
210*a1a3b679SAndreas Boehler    function getACL() {
211*a1a3b679SAndreas Boehler
212*a1a3b679SAndreas Boehler        return [
213*a1a3b679SAndreas Boehler            [
214*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
215*a1a3b679SAndreas Boehler                'principal' => $this->getOwner(),
216*a1a3b679SAndreas Boehler                'protected' => true,
217*a1a3b679SAndreas Boehler            ],
218*a1a3b679SAndreas Boehler            [
219*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}write',
220*a1a3b679SAndreas Boehler                'principal' => $this->getOwner(),
221*a1a3b679SAndreas Boehler                'protected' => true,
222*a1a3b679SAndreas Boehler            ],
223*a1a3b679SAndreas Boehler            [
224*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
225*a1a3b679SAndreas Boehler                'principal' => $this->getOwner() . '/calendar-proxy-write',
226*a1a3b679SAndreas Boehler                'protected' => true,
227*a1a3b679SAndreas Boehler            ],
228*a1a3b679SAndreas Boehler            [
229*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}write',
230*a1a3b679SAndreas Boehler                'principal' => $this->getOwner() . '/calendar-proxy-write',
231*a1a3b679SAndreas Boehler                'protected' => true,
232*a1a3b679SAndreas Boehler            ],
233*a1a3b679SAndreas Boehler            [
234*a1a3b679SAndreas Boehler                'privilege' => '{DAV:}read',
235*a1a3b679SAndreas Boehler                'principal' => $this->getOwner() . '/calendar-proxy-read',
236*a1a3b679SAndreas Boehler                'protected' => true,
237*a1a3b679SAndreas Boehler            ]
238*a1a3b679SAndreas Boehler        ];
239*a1a3b679SAndreas Boehler
240*a1a3b679SAndreas Boehler    }
241*a1a3b679SAndreas Boehler
242*a1a3b679SAndreas Boehler    /**
243*a1a3b679SAndreas Boehler     * Updates the ACL.
244*a1a3b679SAndreas Boehler     *
245*a1a3b679SAndreas Boehler     * This method will receive a list of new ACE's.
246*a1a3b679SAndreas Boehler     *
247*a1a3b679SAndreas Boehler     * @param array $acl
248*a1a3b679SAndreas Boehler     * @return void
249*a1a3b679SAndreas Boehler     */
250*a1a3b679SAndreas Boehler    function setACL(array $acl) {
251*a1a3b679SAndreas Boehler
252*a1a3b679SAndreas Boehler        throw new MethodNotAllowed('Changing ACL is not yet supported');
253*a1a3b679SAndreas Boehler
254*a1a3b679SAndreas Boehler    }
255*a1a3b679SAndreas Boehler
256*a1a3b679SAndreas Boehler    /**
257*a1a3b679SAndreas Boehler     * Returns the list of supported privileges for this node.
258*a1a3b679SAndreas Boehler     *
259*a1a3b679SAndreas Boehler     * The returned data structure is a list of nested privileges.
260*a1a3b679SAndreas Boehler     * See \Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
261*a1a3b679SAndreas Boehler     * standard structure.
262*a1a3b679SAndreas Boehler     *
263*a1a3b679SAndreas Boehler     * If null is returned from this method, the default privilege set is used,
264*a1a3b679SAndreas Boehler     * which is fine for most common usecases.
265*a1a3b679SAndreas Boehler     *
266*a1a3b679SAndreas Boehler     * @return array|null
267*a1a3b679SAndreas Boehler     */
268*a1a3b679SAndreas Boehler    function getSupportedPrivilegeSet() {
269*a1a3b679SAndreas Boehler
270*a1a3b679SAndreas Boehler        return null;
271*a1a3b679SAndreas Boehler
272*a1a3b679SAndreas Boehler    }
273*a1a3b679SAndreas Boehler
274*a1a3b679SAndreas Boehler}
275