11<?php
22
3+ /**
4+ * PDO CalDAV backend
5+ *
6+ * This backend is used to store calendar-data in a PDO database, such as
7+ * sqlite or MySQL
8+ *
9+ * @package Sabre
10+ * @subpackage CalDAV
11+ * @version $Id$
12+ * @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
13+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
14+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15+ */
316class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
417
18+ /**
19+ * pdo
20+ *
21+ * @var PDO
22+ */
523 private $ pdo ;
624
25+ /**
26+ * List of CalDAV properties, and how they map to database fieldnames
27+ *
28+ * Add your own properties by simply adding on to this array
29+ *
30+ * @var array
31+ */
732 public $ propertyMap = array (
833 '{DAV:}displayname ' => 'displayname ' ,
934 '{urn:ietf:params:xml:ns:caldav}description ' => 'description ' ,
1035 '{http://apple.com/ns/ical/}calendar-order ' => 'calendarorder ' ,
1136 '{http://apple.com/ns/ical/}calendar-color ' => 'calendarcolor ' ,
1237 );
1338
14- function __construct (PDO $ pdo ) {
39+ /**
40+ * Creates the backend
41+ *
42+ * @param PDO $pdo
43+ */
44+ public function __construct (PDO $ pdo ) {
1545
1646 $ this ->pdo = $ pdo ;
1747
1848 }
1949
20- function getCalendarsForUser ($ principalUri ) {
50+ /**
51+ * Returns a list of calendars for a principal
52+ *
53+ * @param string $userUri
54+ * @return array
55+ */
56+ public function getCalendarsForUser ($ principalUri ) {
2157
2258 $ fields = array_values ($ this ->propertyMap );
2359 $ fields [] = 'id ' ;
@@ -46,7 +82,18 @@ function getCalendarsForUser($principalUri) {
4682
4783 }
4884
49- function createCalendar ($ principalUri ,$ calendarUri , array $ properties ) {
85+ /**
86+ * Creates a new calendar for a principal.
87+ *
88+ * If the creation was a success, an id must be returned that can be used to reference
89+ * this calendar in other methods, such as updateCalendar
90+ *
91+ * @param string $principalUri
92+ * @param string $calendarUri
93+ * @param array $properties
94+ * @return mixed
95+ */
96+ public function createCalendar ($ principalUri ,$ calendarUri , array $ properties ) {
5097
5198 $ fieldNames = array (
5299 'principaluri ' ,
@@ -71,7 +118,29 @@ function createCalendar($principalUri,$calendarUri, array $properties) {
71118
72119 }
73120
74- function updateCalendar ($ calendarId , array $ mutations ) {
121+ /**
122+ * Updates a calendar's properties
123+ *
124+ *
125+ * The mutations array has 3 elements for each item. The first indicates if the property
126+ * is to be removed or updated (Sabre_DAV_Server::PROP_REMOVE and Sabre_DAV_Server::PROP_SET)
127+ * the second is the propertyName in Clark notation, the third is the actual value (ommitted
128+ * if the property is to be deleted).
129+ *
130+ * The result of this method should be another array. Each element has 2 subelements with the
131+ * propertyname and statuscode for the change
132+ *
133+ * For example:
134+ * array(array('{DAV:}prop1',200), array('{DAV:}prop2',200), array('{DAV:}prop3',403))
135+ *
136+ * The default implementation does not allow any properties to be updated, and thus
137+ * will return 403 for each one.
138+ *
139+ * @param string $calendarId
140+ * @param array $mutations
141+ * @return array
142+ */
143+ public function updateCalendar ($ calendarId , array $ mutations ) {
75144
76145 $ values = array ();
77146
@@ -113,7 +182,13 @@ function updateCalendar($calendarId, array $mutations) {
113182
114183 }
115184
116- function deleteCalendar ($ calendarId ) {
185+ /**
186+ * Delete a calendar and all it's objects
187+ *
188+ * @param string $calendarId
189+ * @return void
190+ */
191+ public function deleteCalendar ($ calendarId ) {
117192
118193 $ stmt = $ this ->pdo ->prepare ('DELETE FROM calendarobjects WHERE calendarid = ? ' );
119194 $ stmt ->execute (array ($ calendarId ));
@@ -123,37 +198,73 @@ function deleteCalendar($calendarId) {
123198
124199 }
125200
126- function getCalendarObjects ($ calendarId ) {
201+ /**
202+ * Returns all calendar objects within a calendar object.
203+ *
204+ * @param string $calendarId
205+ * @return array
206+ */
207+ public function getCalendarObjects ($ calendarId ) {
127208
128209 $ stmt = $ this ->pdo ->prepare ('SELECT * FROM calendarobjects WHERE calendarid = ? ' );
129210 $ stmt ->execute (array ($ calendarId ));
130211 return $ stmt ->fetchAll ();
131212
132213 }
133214
134- function getCalendarObject ($ calendarId ,$ objectUri ) {
215+ /**
216+ * Returns information from a single calendar object, based on it's object uri.
217+ *
218+ * @param string $calendarId
219+ * @param string $objectUri
220+ * @return array
221+ */
222+ public function getCalendarObject ($ calendarId ,$ objectUri ) {
135223
136224 $ stmt = $ this ->pdo ->prepare ('SELECT * FROM calendarobjects WHERE calendarid = ? AND uri = ? ' );
137225 $ stmt ->execute (array ($ calendarId , $ objectUri ));
138226 return $ stmt ->fetch ();
139227
140228 }
141229
142- function createCalendarObject ($ calendarId ,$ objectUri ,$ calendarData ) {
230+ /**
231+ * Creates a new calendar object.
232+ *
233+ * @param string $calendarId
234+ * @param string $objectUri
235+ * @param string $calendarData
236+ * @return void
237+ */
238+ public function createCalendarObject ($ calendarId ,$ objectUri ,$ calendarData ) {
143239
144240 $ stmt = $ this ->pdo ->prepare ('INSERT INTO calendarobjects (calendarid, uri, calendardata, lastmodified) VALUES (?,?,?,?) ' );
145241 $ stmt ->execute (array ($ calendarId ,$ objectUri ,$ calendarData ,time ()));
146242
147243 }
148244
149- function updateCalendarObject ($ calendarId ,$ objectUri ,$ calendarData ) {
245+ /**
246+ * Updates an existing calendarobject, based on it's uri.
247+ *
248+ * @param string $calendarId
249+ * @param string $objectUri
250+ * @param string $calendarData
251+ * @return void
252+ */
253+ public function updateCalendarObject ($ calendarId ,$ objectUri ,$ calendarData ) {
150254
151255 $ stmt = $ this ->pdo ->prepare ('UPDATE calendarobjects SET calendardata = ?, lastmodified = ? WHERE calendarid = ? AND uri = ? ' );
152256 $ stmt ->execute (array ($ calendarData ,time (),$ calendarId ,$ objectUri ));
153257
154258 }
155259
156- function deleteCalendarObject ($ calendarId ,$ objectUri ) {
260+ /**
261+ * Deletes an existing calendar object.
262+ *
263+ * @param string $calendarId
264+ * @param string $objectUri
265+ * @return void
266+ */
267+ public function deleteCalendarObject ($ calendarId ,$ objectUri ) {
157268
158269 $ stmt = $ this ->pdo ->prepare ('DELETE FROM calendarobjects WHERE calendarid = ? AND uri = ? ' );
159270 $ stmt ->execute (array ($ calendarId ,$ objectUri ));
0 commit comments