4 * This object represents a CalDAV calendar.
6 * A calendar can contain multiple TODO and or Events. These are represented
7 * as Sabre_CalDAV_CalendarObject objects.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class Sabre_CalDAV_Calendar implements Sabre_CalDAV_ICalendar, Sabre_DAV_IProperties, Sabre_DAVACL_IACL {
18 * This is an array with calendar information
22 protected $calendarInfo;
27 * @var Sabre_CalDAV_Backend_BackendInterface
29 protected $caldavBackend;
34 * @var Sabre_DAVACL_IPrincipalBackend
36 protected $principalBackend;
41 * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
42 * @param Sabre_CalDAV_Backend_BackendInterface $caldavBackend
43 * @param array $calendarInfo
45 public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_BackendInterface $caldavBackend, $calendarInfo) {
47 $this->caldavBackend = $caldavBackend;
48 $this->principalBackend = $principalBackend;
49 $this->calendarInfo = $calendarInfo;
55 * Returns the name of the calendar
59 public function getName() {
61 return $this->calendarInfo['uri'];
66 * Updates properties such as the display name and description
68 * @param array $mutations
71 public function updateProperties($mutations) {
73 return $this->caldavBackend->updateCalendar($this->calendarInfo['id'],$mutations);
78 * Returns the list of properties
80 * @param array $requestedProperties
83 public function getProperties($requestedProperties) {
87 foreach($requestedProperties as $prop) switch($prop) {
89 case '{urn:ietf:params:xml:ns:caldav}supported-calendar-data' :
90 $response[$prop] = new Sabre_CalDAV_Property_SupportedCalendarData();
92 case '{urn:ietf:params:xml:ns:caldav}supported-collation-set' :
93 $response[$prop] = new Sabre_CalDAV_Property_SupportedCollationSet();
96 $response[$prop] = new Sabre_DAVACL_Property_Principal(Sabre_DAVACL_Property_Principal::HREF,$this->calendarInfo['principaluri']);
99 if (isset($this->calendarInfo[$prop])) $response[$prop] = $this->calendarInfo[$prop];
108 * Returns a calendar object
110 * The contained calendar objects are for example Events or Todo's.
112 * @param string $name
113 * @return Sabre_CalDAV_ICalendarObject
115 public function getChild($name) {
117 $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'],$name);
118 if (!$obj) throw new Sabre_DAV_Exception_NotFound('Calendar object not found');
119 return new Sabre_CalDAV_CalendarObject($this->caldavBackend,$this->calendarInfo,$obj);
124 * Returns the full list of calendar objects
128 public function getChildren() {
130 $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
132 foreach($objs as $obj) {
133 $children[] = new Sabre_CalDAV_CalendarObject($this->caldavBackend,$this->calendarInfo,$obj);
140 * Checks if a child-node exists.
142 * @param string $name
145 public function childExists($name) {
147 $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'],$name);
156 * Creates a new directory
158 * We actually block this, as subdirectories are not allowed in calendars.
160 * @param string $name
163 public function createDirectory($name) {
165 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating collections in calendar objects is not allowed');
172 * The contents of the new file must be a valid ICalendar string.
174 * @param string $name
175 * @param resource $calendarData
176 * @return string|null
178 public function createFile($name,$calendarData = null) {
180 if (is_resource($calendarData)) {
181 $calendarData = stream_get_contents($calendarData);
183 return $this->caldavBackend->createCalendarObject($this->calendarInfo['id'],$name,$calendarData);
188 * Deletes the calendar.
192 public function delete() {
194 $this->caldavBackend->deleteCalendar($this->calendarInfo['id']);
199 * Renames the calendar. Note that most calendars use the
200 * {DAV:}displayname to display a name to display a name.
202 * @param string $newName
205 public function setName($newName) {
207 throw new Sabre_DAV_Exception_MethodNotAllowed('Renaming calendars is not yet supported');
212 * Returns the last modification date as a unix timestamp.
216 public function getLastModified() {
223 * Returns the owner principal
225 * This must be a url to a principal, or null if there's no owner
227 * @return string|null
229 public function getOwner() {
231 return $this->calendarInfo['principaluri'];
236 * Returns a group principal
238 * This must be a url to a principal, or null if there's no owner
240 * @return string|null
242 public function getGroup() {
249 * Returns a list of ACE's for this node.
251 * Each ACE has the following properties:
252 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
253 * currently the only supported privileges
254 * * 'principal', a url to the principal who owns the node
255 * * 'protected' (optional), indicating that this ACE is not allowed to
260 public function getACL() {
264 'privilege' => '{DAV:}read',
265 'principal' => $this->calendarInfo['principaluri'],
269 'privilege' => '{DAV:}write',
270 'principal' => $this->calendarInfo['principaluri'],
274 'privilege' => '{DAV:}read',
275 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
279 'privilege' => '{DAV:}write',
280 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
284 'privilege' => '{DAV:}read',
285 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read',
289 'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
290 'principal' => '{DAV:}authenticated',
301 * This method will receive a list of new ACE's.
306 public function setACL(array $acl) {
308 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
313 * Returns the list of supported privileges for this node.
315 * The returned data structure is a list of nested privileges.
316 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
317 * standard structure.
319 * If null is returned from this method, the default privilege set is used,
320 * which is fine for most common usecases.
324 public function getSupportedPrivilegeSet() {
326 $default = Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet();
328 // We need to inject 'read-free-busy' in the tree, aggregated under
330 foreach($default['aggregates'] as &$agg) {
332 if ($agg['privilege'] !== '{DAV:}read') continue;
334 $agg['aggregates'][] = array(
335 'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
344 * Performs a calendar-query on the contents of this calendar.
346 * The calendar-query is defined in RFC4791 : CalDAV. Using the
347 * calendar-query it is possible for a client to request a specific set of
348 * object, based on contents of iCalendar properties, date-ranges and
349 * iCalendar component types (VTODO, VEVENT).
351 * This method should just return a list of (relative) urls that match this
354 * The list of filters are specified as an array. The exact array is
355 * documented by Sabre_CalDAV_CalendarQueryParser.
357 * @param array $filters
360 public function calendarQuery(array $filters) {
362 return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);