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_Abstract
26 protected $caldavBackend;
29 * Principal information
33 protected $principalInfo;
38 * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
39 * @param Sabre_CalDAV_Backend_Abstract $caldavBackend
40 * @param mixed $userUri
42 public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, Sabre_CalDAV_Backend_Abstract $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']);
179 * Creates a new calendar
181 * @param string $name
182 * @param array $resourceType
183 * @param array $properties
186 public function createExtendedCollection($name, array $resourceType, array $properties) {
188 if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar',$resourceType) || count($resourceType)!==2) {
189 throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
191 $this->caldavBackend->createCalendar($this->principalInfo['uri'], $name, $properties);
196 * Returns the owner principal
198 * This must be a url to a principal, or null if there's no owner
200 * @return string|null
202 public function getOwner() {
204 return $this->principalInfo['uri'];
209 * Returns a group principal
211 * This must be a url to a principal, or null if there's no owner
213 * @return string|null
215 public function getGroup() {
222 * Returns a list of ACE's for this node.
224 * Each ACE has the following properties:
225 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
226 * currently the only supported privileges
227 * * 'principal', a url to the principal who owns the node
228 * * 'protected' (optional), indicating that this ACE is not allowed to
233 public function getACL() {
237 'privilege' => '{DAV:}read',
238 'principal' => $this->principalInfo['uri'],
242 'privilege' => '{DAV:}write',
243 'principal' => $this->principalInfo['uri'],
247 'privilege' => '{DAV:}read',
248 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
252 'privilege' => '{DAV:}write',
253 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-write',
257 'privilege' => '{DAV:}read',
258 'principal' => $this->principalInfo['uri'] . '/calendar-proxy-read',
269 * This method will receive a list of new ACE's.
274 public function setACL(array $acl) {
276 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
281 * Returns the list of supported privileges for this node.
283 * The returned data structure is a list of nested privileges.
284 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
285 * standard structure.
287 * If null is returned from this method, the default privilege set is used,
288 * which is fine for most common usecases.
292 public function getSupportedPrivilegeSet() {