4 * The UserCalenders class contains all calendars associated to one user
8 * @copyright Copyright (C) 2007-2012 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
12 class Sabre_CalDAV_UserCalendars implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
17 * @var Sabre_DAVACL_IPrincipalBackend
19 protected $principalBackend;
24 * @var Sabre_CalDAV_Backend_BackendInterface
26 protected $caldavBackend;
29 * Principal information
33 protected $principalInfo;
38 * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
39 * @param Sabre_CalDAV_Backend_BackendInterface $caldavBackend
40 * @param mixed $userUri
42 public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_BackendInterface $caldavBackend, $userUri) {
44 $this->principalBackend = $principalBackend;
45 $this->caldavBackend = $caldavBackend;
46 $this->principalInfo = $principalBackend->getPrincipalByPath($userUri);
51 * Returns the name of this object
55 public function getName() {
57 list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalInfo['uri']);
63 * Updates the name of this object
68 public function setName($name) {
70 throw new Sabre_DAV_Exception_Forbidden();
79 public function delete() {
81 throw new Sabre_DAV_Exception_Forbidden();
86 * Returns the last modification date
90 public function getLastModified() {
97 * Creates a new file under this object.
99 * This is currently not allowed
101 * @param string $filename
102 * @param resource $data
105 public function createFile($filename, $data=null) {
107 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
112 * Creates a new directory under this object.
114 * This is currently not allowed.
116 * @param string $filename
119 public function createDirectory($filename) {
121 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
126 * Returns a single calendar, by name
128 * @param string $name
129 * @todo needs optimizing
130 * @return Sabre_CalDAV_Calendar
132 public function getChild($name) {
134 foreach($this->getChildren() as $child) {
135 if ($name==$child->getName())
139 throw new Sabre_DAV_Exception_NotFound('Calendar with name \'' . $name . '\' could not be found');
144 * Checks if a calendar exists.
146 * @param string $name
147 * @todo needs optimizing
150 public function childExists($name) {
152 foreach($this->getChildren() as $child) {
153 if ($name==$child->getName())
162 * Returns a list of calendars
166 public function getChildren() {
168 $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
170 foreach($calendars as $calendar) {
171 $objs[] = new Sabre_CalDAV_Calendar($this->principalBackend, $this->caldavBackend, $calendar);
173 $objs[] = new Sabre_CalDAV_Schedule_Outbox($this->principalInfo['uri']);
175 // We're adding a notifications node, if it's supported by the backend.
176 if ($this->caldavBackend instanceof Sabre_CalDAV_Backend_NotificationSupport) {
177 $objs[] = new Sabre_CalDAV_Notifications_Collection($this->caldavBackend, $this->principalInfo['uri']);
184 * Creates a new calendar
186 * @param string $name
187 * @param array $resourceType
188 * @param array $properties
191 public function createExtendedCollection($name, array $resourceType, array $properties) {
193 if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) {
194 throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
196 $this->caldavBackend->createCalendar($this->principalInfo['uri'], $name, $properties);
201 * Returns the owner principal
203 * This must be a url to a principal, or null if there's no owner
205 * @return string|null
207 public function getOwner() {
209 return $this->principalInfo['uri'];
214 * Returns a group principal
216 * This must be a url to a principal, or null if there's no owner
218 * @return string|null
220 public function getGroup() {
227 * Returns a list of ACE's for this node.
229 * Each ACE has the following properties:
230 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
231 * currently the only supported privileges
232 * * 'principal', a url to the principal who owns the node
233 * * 'protected' (optional), indicating that this ACE is not allowed to
238 public function getACL() {
242 'privilege' => '{DAV:}read',
243 'principal' => $this->principalInfo['uri'],
247 'privilege' => '{DAV:}write',
248 'principal' => $this->principalInfo['uri'],
252 'privilege' => '{DAV:}read',
253 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
257 'privilege' => '{DAV:}write',
258 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
262 'privilege' => '{DAV:}read',
263 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
274 * This method will receive a list of new ACE's.
279 public function setACL(array $acl) {
281 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
286 * Returns the list of supported privileges for this node.
288 * The returned data structure is a list of nested privileges.
289 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
290 * standard structure.
292 * If null is returned from this method, the default privilege set is used,
293 * which is fine for most common usecases.
297 public function getSupportedPrivilegeSet() {