1: <?php
2: /**
3: * This class implements a Horde CalDAV backend for SabreDAV.
4: *
5: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
6: *
7: * @package Sabre
8: * @author Jan Schneider <jan@horde.org>
9: * @license @todo
10: */
11: class Sabre_CalDAV_Backend_Horde extends Sabre_CalDAV_Backend_Abstract
12: {
13: /**
14: * @var Horde_Registry
15: */
16: protected $_registry;
17:
18: public function __construct(Horde_Registry $registry)
19: {
20: $this->_registry = $registry;
21: }
22:
23: /**
24: * Returns a list of calendars for a users' uri
25: *
26: * The uri is not a full path, just the actual last part
27: *
28: * @param string $userUri
29: * @return array
30: */
31: public function getCalendarsForUser($userUri)
32: {
33: // If possible we should ressamble the existing WebDAV structure with
34: // CalDAV. Listing just the calendars is not sufficient for this.
35: $result = array();
36: $owners = $this->_registry->calendar->browse('', array('name'));
37: foreach (reset($owners) as $owner) {
38: $calendars = $this->_registry->calendar->browse($owner['name'], array('name'));
39: foreach ($calendars as $name => $calendar) {
40: $result[] = substr($name, strrpos($name, '/'));
41: }
42: }
43: return $result;
44:
45: // Alternative solution (without hierarchy):
46: return $this->_registry->calendar->listCalendars();
47: }
48:
49: /**
50: * Creates a new calendar for a user
51: *
52: * The userUri and calendarUri are not full paths, just the 'basename'.
53: *
54: * @param string $userUri
55: * @param string $calendarUri
56: * @param string $displayName
57: * @param string $description
58: * @return void
59: */
60: public function createCalendar($userUri, $calendarUri, $displayName,
61: $description)
62: {
63: // To be implemented. We can't create the Horde_Share directly,
64: // because each application defines its own share namespace
65: // (e.g. horde.shares.kronolith), but this namespace is unknown
66: // outside of the application.
67: // Why Uri? Is it anything different than the plain user name and
68: // calendar ID?
69: $this->_registry->calendar->createCalendar($userUri, $calendarUri, $displayName, $description);
70: }
71:
72: /**
73: * Updates a calendar's basic information
74: *
75: * @param string $calendarId
76: * @param string $displayName
77: * @param string $description
78: * @return void
79: */
80: public function updateCalendar($calendarId, $displayName, $description)
81: {
82: // To be implemented.
83: // ID == calendar name in Horde.
84: $this->_registry->calendar->updateCalendar($calendarId, $displayName, $description);
85: }
86:
87: /**
88: * Returns all calendar objects within a calendar object.
89: *
90: * @param string $calendarId
91: * @return array
92: */
93: public function getCalendarObjects($calendarId)
94: {
95: // browse() assumes an intermediate owner directory at the moment.
96: $owner = 'foo';
97: $events = $this->_registry->calendar->browse($owner . '/' . $calendarId, array('name'));
98:
99: // Return format?
100: return $events;
101: }
102:
103: /**
104: * Returns information from a single calendar object, based on it's object
105: * uri.
106: *
107: * @param mixed $calendarId
108: * @param string $objectUri
109: * @return array
110: */
111: public function getCalendarObject($calendarId, $objectUri)
112: {
113: // browse() assumes an intermediate owner directory at the moment.
114: $owner = 'foo';
115: $event = $this->_registry->calendar->browse($owner . '/' . $calendarId . '/' . $objectUri);
116: return array('calendardata' => $event['data'],
117: 'lastmodified' => $event['mtime']);
118: // What else to return? Mime type?
119: }
120:
121: /**
122: * Creates a new calendar object.
123: *
124: * @param mixed $calendarId
125: * @param string $objectUri
126: * @param string $calendarData
127: * @return void
128: */
129: public function createCalendarObject($calendarId, $objectUri, $calendarData)
130: {
131: // No Content-Type?
132: // We don't accept object ids at the moment.
133: $this->_registry->import($calendarData, 'text/calendar', $calendarId);
134: }
135:
136: /**
137: * Updates an existing calendarobject, based on it's uri.
138: *
139: * @param mixed $calendarId
140: * @param string $objectUri
141: * @param string $calendarData
142: * @return void
143: */
144: public function updateCalendarObject($calendarId, $objectUri, $calendarData)
145: {
146: // No Content-Type?
147: // Object ID or UID?
148: $this->_registry->import($objectUri, $calendarData, 'text/calendar');
149: }
150:
151: /**
152: * Deletes an existing calendar object.
153: *
154: * @param mixed $calendarId
155: * @param string $objectUri
156: * @return void
157: */
158: public function deleteCalendarObject($calendarId, $objectUri)
159: {
160: // Object ID or UID?
161: $this->_registry->delete($objectUri);
162: }
163:
164: }
165: