4 * The CalendarObject represents a single VEVENT or VTODO within a Calendar.
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_CalendarObject extends Sabre_DAV_File implements Sabre_CalDAV_ICalendarObject, Sabre_DAVACL_IACL {
15 * Sabre_CalDAV_Backend_BackendInterface
19 protected $caldavBackend;
22 * Array with information about this CalendarObject
26 protected $objectData;
29 * Array with information about the containing calendar
33 protected $calendarInfo;
38 * @param Sabre_CalDAV_Backend_BackendInterface $caldavBackend
39 * @param array $calendarInfo
40 * @param array $objectData
42 public function __construct(Sabre_CalDAV_Backend_BackendInterface $caldavBackend,array $calendarInfo,array $objectData) {
44 $this->caldavBackend = $caldavBackend;
46 if (!isset($objectData['calendarid'])) {
47 throw new InvalidArgumentException('The objectData argument must contain a \'calendarid\' property');
49 if (!isset($objectData['uri'])) {
50 throw new InvalidArgumentException('The objectData argument must contain an \'uri\' property');
53 $this->calendarInfo = $calendarInfo;
54 $this->objectData = $objectData;
59 * Returns the uri for this object
63 public function getName() {
65 return $this->objectData['uri'];
70 * Returns the ICalendar-formatted object
74 public function get() {
76 // Pre-populating the 'calendardata' is optional, if we don't have it
77 // already we fetch it from the backend.
78 if (!isset($this->objectData['calendardata'])) {
79 $this->objectData = $this->caldavBackend->getCalendarObject($this->objectData['calendarid'], $this->objectData['uri']);
81 return $this->objectData['calendardata'];
86 * Updates the ICalendar-formatted object
88 * @param string|resource $calendarData
91 public function put($calendarData) {
93 if (is_resource($calendarData)) {
94 $calendarData = stream_get_contents($calendarData);
96 $etag = $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'],$this->objectData['uri'],$calendarData);
97 $this->objectData['calendardata'] = $calendarData;
98 $this->objectData['etag'] = $etag;
105 * Deletes the calendar object
109 public function delete() {
111 $this->caldavBackend->deleteCalendarObject($this->calendarInfo['id'],$this->objectData['uri']);
116 * Returns the mime content-type
120 public function getContentType() {
122 return 'text/calendar; charset=utf-8';
127 * Returns an ETag for this object.
129 * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
133 public function getETag() {
135 if (isset($this->objectData['etag'])) {
136 return $this->objectData['etag'];
138 return '"' . md5($this->get()). '"';
144 * Returns the last modification date as a unix timestamp
148 public function getLastModified() {
150 return $this->objectData['lastmodified'];
155 * Returns the size of this object in bytes
159 public function getSize() {
161 if (array_key_exists('size',$this->objectData)) {
162 return $this->objectData['size'];
164 return strlen($this->get());
170 * Returns the owner principal
172 * This must be a url to a principal, or null if there's no owner
174 * @return string|null
176 public function getOwner() {
178 return $this->calendarInfo['principaluri'];
183 * Returns a group principal
185 * This must be a url to a principal, or null if there's no owner
187 * @return string|null
189 public function getGroup() {
196 * Returns a list of ACE's for this node.
198 * Each ACE has the following properties:
199 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
200 * currently the only supported privileges
201 * * 'principal', a url to the principal who owns the node
202 * * 'protected' (optional), indicating that this ACE is not allowed to
207 public function getACL() {
211 'privilege' => '{DAV:}read',
212 'principal' => $this->calendarInfo['principaluri'],
216 'privilege' => '{DAV:}write',
217 'principal' => $this->calendarInfo['principaluri'],
221 'privilege' => '{DAV:}read',
222 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
226 'privilege' => '{DAV:}write',
227 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-write',
231 'privilege' => '{DAV:}read',
232 'principal' => $this->calendarInfo['principaluri'] . '/calendar-proxy-read',
243 * This method will receive a list of new ACE's.
248 public function setACL(array $acl) {
250 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
255 * Returns the list of supported privileges for this node.
257 * The returned data structure is a list of nested privileges.
258 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
259 * standard structure.
261 * If null is returned from this method, the default privilege set is used,
262 * which is fine for most common usecases.
266 public function getSupportedPrivilegeSet() {