Skip to content

Commit 4479091

Browse files
committed
Docblocks
1 parent 4a20635 commit 4479091

File tree

5 files changed

+239
-14
lines changed

5 files changed

+239
-14
lines changed

lib/Sabre/CalDAV/Backend/PDO.php

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,59 @@
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+
*/
316
class 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));

lib/Sabre/CalDAV/Plugin.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@
1515
*/
1616
class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
1717

18+
/**
19+
* This is the official CalDAV namespace
20+
*/
1821
const NS_CALDAV = 'urn:ietf:params:xml:ns:caldav';
1922

23+
/**
24+
* The following constants are used to differentiate
25+
* the various filters for the calendar-query report
26+
*/
2027
const FILTER_COMPFILTER = 1;
2128
const FILTER_ISNOTDEFINED = 2;
2229
const FILTER_TIMERANGE = 3;
2330
const FILTER_PROPFILTER = 4;
2431
const FILTER_PARAMFILTER = 5;
2532
const FILTER_TEXTMATCH = 6;
2633

34+
/**
35+
* The hardcoded root for calendar objects. It is unfortunate
36+
* that we're stuck with it, but it will have to do for now
37+
*/
2738
const CALENDAR_ROOT = 'calendars';
2839

2940
/**
@@ -316,6 +327,15 @@ public function calendarQueryReport($dom) {
316327
}
317328

318329

330+
/**
331+
* This function parses the calendar-query report request body
332+
*
333+
* The body is quite complicated, so we're turning it into a PHP
334+
* array.
335+
*
336+
* @param DOMNode $domNode
337+
* @return array
338+
*/
319339
protected function parseFilters($domNode) {
320340

321341
$filters = array();
@@ -388,6 +408,16 @@ protected function parseFilters($domNode) {
388408

389409
}
390410

411+
/**
412+
* Verify if a list of filters applies to the calendar data object
413+
*
414+
* The calendarData object must be a valid iCalendar blob. The list of
415+
* filters must be formatted as parsed by Sabre_CalDAV_Plugin::parseFilters
416+
*
417+
* @param string $calendarData
418+
* @param array $filters
419+
* @return bool
420+
*/
391421
protected function validateFilters($calendarData,$filters) {
392422

393423
// We are converting the calendar object to an XML structure
@@ -399,6 +429,16 @@ protected function validateFilters($calendarData,$filters) {
399429

400430
}
401431

432+
/**
433+
* This function is simply used by validateFilters
434+
*
435+
* A separete function was needed, because it nees to be a recursive function
436+
*
437+
* @param SimpleXMLElement $xNode
438+
* @param array $filters
439+
* @param string $xpath
440+
* @return bool
441+
*/
402442
protected function validateXMLFilters($xNode,$filters,$xpath = '/c:iCalendar') {
403443

404444
foreach($filters as $filter) {

lib/Sabre/CalDAV/Property/SupportedCalendarComponentSet.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
11
<?php
22

3+
/**
4+
* Sabre_CalDAV_Property_SupportedCalendarComponentSet
5+
*
6+
* @package Sabre
7+
* @version $Id$
8+
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
9+
* @author Evert Pot (http://www.rooftopsolutions.nl/)
10+
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11+
*/
12+
13+
/**
14+
* Supported component set property
15+
*
16+
* This property is a representation of the supported-component-set property
17+
* in the CalDAV namespace. It simply requires an array of components, such as
18+
* VEVENT, VTODO
19+
*/
320
class Sabre_CalDAV_Property_SupportedCalendarComponentSet extends Sabre_DAV_Property {
421

22+
/**
23+
* components
24+
*
25+
* @var array
26+
*/
527
private $components;
628

7-
function __construct(array $components) {
29+
/**
30+
* Creates the property
31+
*
32+
* @param array $components
33+
*/
34+
public function __construct(array $components) {
835

936
$this->components = $components;
1037

1138
}
1239

13-
function serialize(Sabre_DAV_Server $server,DOMElement $node) {
40+
/**
41+
* Serializes the property in a DOMDocument
42+
*
43+
* @param Sabre_DAV_Server $server
44+
* @param DOMElement $node
45+
* @return void
46+
*/
47+
public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
1448

1549
$doc = $node->ownerDocument;
1650
foreach($this->components as $component) {

lib/Sabre/CalDAV/Property/SupportedCalendarData.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
<?php
22

3+
/**
4+
* Sabre_CalDAV_Property_SupportedCalendarData
5+
*
6+
* @package Sabre
7+
* @version $Id$
8+
* @copyright Copyright (C) 2007-2010 Rooftop Solutions. All rights reserved.
9+
* @author Evert Pot (http://www.rooftopsolutions.nl/)
10+
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11+
*/
12+
13+
/**
14+
* supported-calendar-data property
15+
*
16+
* This property is a representation of the supported-calendar-data property
17+
* in the CalDAV namespace. SabreDAV only has support for text/calendar;2.0
18+
* so the value is currently hardcoded.
19+
*/
320
class Sabre_CalDAV_Property_SupportedCalendarData extends Sabre_DAV_Property {
421

5-
function serialize(Sabre_DAV_Server $server,DOMElement $node) {
22+
/**
23+
* Serializes the property in a DOMDocument
24+
*
25+
* @param Sabre_DAV_Server $server
26+
* @param DOMElement $node
27+
* @return void
28+
*/
29+
public function serialize(Sabre_DAV_Server $server,DOMElement $node) {
630

731
$doc = $node->ownerDocument;
832

@@ -13,7 +37,6 @@ function serialize(Sabre_DAV_Server $server,DOMElement $node) {
1337
$caldata->setAttribute('version','2.0');
1438

1539
$node->appendChild($caldata);
16-
1740
}
1841

1942
}

0 commit comments

Comments
 (0)