4 * The UserCalenders class contains all calendars associated to one user
8 * @copyright Copyright (C) 2007-2011 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_CardDAV_UserAddressBooksMultiBackend extends Sabre_DAV_Collection implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
19 protected $principalUri;
24 * @var array|Sabre_CardDAV_Backend_Abstract[]
26 protected $carddavBackends;
31 * @param array|Sabre_CardDAV_Backend_Abstract[] $carddavBackends
32 * @param string $principalUri
34 public function __construct($carddavBackends, $principalUri) {
36 $this->carddavBackends = $carddavBackends;
37 $this->principalUri = $principalUri;
42 * Returns the name of this object
46 public function getName() {
48 list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalUri);
54 * Updates the name of this object
57 * @throws Sabre_DAV_Exception_MethodNotAllowed
60 public function setName($name) {
62 throw new Sabre_DAV_Exception_MethodNotAllowed();
69 * @throws Sabre_DAV_Exception_MethodNotAllowed
72 public function delete() {
74 throw new Sabre_DAV_Exception_MethodNotAllowed();
79 * Returns the last modification date
83 public function getLastModified() {
90 * Creates a new file under this object.
92 * This is currently not allowed
94 * @param string $filename
95 * @param resource $data
96 * @throws Sabre_DAV_Exception_MethodNotAllowed
97 * @return null|string|void
99 public function createFile($filename, $data=null) {
101 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
106 * Creates a new directory under this object.
108 * This is currently not allowed.
110 * @param string $filename
111 * @throws Sabre_DAV_Exception_MethodNotAllowed
114 public function createDirectory($filename) {
116 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
121 * Returns a single calendar, by name
123 * @param string $name
124 * @throws Sabre_DAV_Exception_NotFound
125 * @todo needs optimizing
126 * @return \Sabre_CardDAV_AddressBook|\Sabre_DAV_INode
128 public function getChild($name) {
130 foreach($this->getChildren() as $child) {
131 if ($name==$child->getName())
135 throw new Sabre_DAV_Exception_NotFound('Addressbook with name \'' . $name . '\' could not be found');
140 * Returns a list of addressbooks
142 * @return array|Sabre_DAV_INode[]
144 public function getChildren() {
147 foreach ($this->carddavBackends as $backend) {
148 $addressbooks = $backend->getAddressbooksForUser($this->principalUri);
149 foreach($addressbooks as $addressbook) {
150 $objs[] = new Sabre_CardDAV_AddressBook($backend, $addressbook);
158 * Creates a new addressbook
160 * @param string $name
161 * @param array $resourceType
162 * @param array $properties
163 * @throws Sabre_DAV_Exception_InvalidResourceType
166 public function createExtendedCollection($name, array $resourceType, array $properties) {
168 if (!in_array('{'.Sabre_CardDAV_Plugin::NS_CARDDAV.'}addressbook',$resourceType) || count($resourceType)!==2) {
169 throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
171 $this->carddavBackends[0]->createAddressBook($this->principalUri, $name, $properties);
176 * Returns the owner principal
178 * This must be a url to a principal, or null if there's no owner
180 * @return string|null
182 public function getOwner() {
184 return $this->principalUri;
189 * Returns a group principal
191 * This must be a url to a principal, or null if there's no owner
193 * @return string|null
195 public function getGroup() {
202 * Returns a list of ACE's for this node.
204 * Each ACE has the following properties:
205 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
206 * currently the only supported privileges
207 * * 'principal', a url to the principal who owns the node
208 * * 'protected' (optional), indicating that this ACE is not allowed to
213 public function getACL() {
217 'privilege' => '{DAV:}read',
218 'principal' => $this->principalUri,
222 'privilege' => '{DAV:}write',
223 'principal' => $this->principalUri,
234 * This method will receive a list of new ACE's.
237 * @throws Sabre_DAV_Exception_MethodNotAllowed
240 public function setACL(array $acl) {
242 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
247 * Returns the list of supported privileges for this node.
249 * The returned data structure is a list of nested privileges.
250 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
251 * standard structure.
253 * If null is returned from this method, the default privilege set is used,
254 * which is fine for most common usecases.
258 public function getSupportedPrivilegeSet() {