]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/CardDAV/UserAddressBooks.php
3f11fb11238ba6274c2dbed7fc19bf9e27c3f290
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / CardDAV / UserAddressBooks.php
1 <?php
2
3 /**
4  * UserAddressBooks class
5  *
6  * The UserAddressBooks collection contains a list of addressbooks associated with a user
7  *
8  * @package Sabre
9  * @subpackage CardDAV
10  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11  * @author Evert Pot (http://www.rooftopsolutions.nl/) 
12  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
13  */
14 class Sabre_CardDAV_UserAddressBooks extends Sabre_DAV_Collection implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
15
16     /**
17      * Principal uri
18      *
19      * @var array
20      */
21     protected $principalUri;
22
23     /**
24      * carddavBackend
25      *
26      * @var Sabre_CardDAV_Backend_Abstract
27      */
28     protected $carddavBackend;
29
30     /**
31      * Constructor
32      *
33      * @param Sabre_CardDAV_Backend_Abstract $carddavBackend
34      * @param string $principalUri
35      */
36     public function __construct(Sabre_CardDAV_Backend_Abstract $carddavBackend, $principalUri) {
37
38         $this->carddavBackend = $carddavBackend;
39         $this->principalUri = $principalUri;
40
41     }
42
43     /**
44      * Returns the name of this object
45      *
46      * @return string
47      */
48     public function getName() {
49
50         list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalUri);
51         return $name;
52
53     }
54
55     /**
56      * Updates the name of this object
57      *
58      * @param string $name
59      * @return void
60      */
61     public function setName($name) {
62
63         throw new Sabre_DAV_Exception_MethodNotAllowed();
64
65     }
66
67     /**
68      * Deletes this object
69      *
70      * @return void
71      */
72     public function delete() {
73
74         throw new Sabre_DAV_Exception_MethodNotAllowed();
75
76     }
77
78     /**
79      * Returns the last modification date
80      *
81      * @return int
82      */
83     public function getLastModified() {
84
85         return null;
86
87     }
88
89     /**
90      * Creates a new file under this object.
91      *
92      * This is currently not allowed
93      *
94      * @param string $filename
95      * @param resource $data
96      * @return void
97      */
98     public function createFile($filename, $data=null) {
99
100         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
101
102     }
103
104     /**
105      * Creates a new directory under this object.
106      *
107      * This is currently not allowed.
108      *
109      * @param string $filename
110      * @return void
111      */
112     public function createDirectory($filename) {
113
114         throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
115
116     }
117
118     /**
119      * Returns a single calendar, by name
120      *
121      * @param string $name
122      * @todo needs optimizing
123      * @return Sabre_CardDAV_AddressBook
124      */
125     public function getChild($name) {
126
127         foreach($this->getChildren() as $child) {
128             if ($name==$child->getName())
129                 return $child;
130
131         }
132         throw new Sabre_DAV_Exception_NotFound('Addressbook with name \'' . $name . '\' could not be found');
133
134     }
135
136     /**
137      * Returns a list of addressbooks
138      *
139      * @return array
140      */
141     public function getChildren() {
142
143         $addressbooks = $this->carddavBackend->getAddressbooksForUser($this->principalUri);
144         $objs = array();
145         foreach($addressbooks as $addressbook) {
146             $objs[] = new Sabre_CardDAV_AddressBook($this->carddavBackend, $addressbook);
147         }
148         return $objs;
149
150     }
151
152     /**
153      * Creates a new addressbook
154      *
155      * @param string $name
156      * @param array $resourceType
157      * @param array $properties
158      * @return void
159      */
160     public function createExtendedCollection($name, array $resourceType, array $properties) {
161
162         if (!in_array('{'.Sabre_CardDAV_Plugin::NS_CARDDAV.'}addressbook',$resourceType) || count($resourceType)!==2) {
163             throw new Sabre_DAV_Exception_InvalidResourceType('Unknown resourceType for this collection');
164         }
165         $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties);
166
167     }
168
169     /**
170      * Returns the owner principal
171      *
172      * This must be a url to a principal, or null if there's no owner
173      *
174      * @return string|null
175      */
176     public function getOwner() {
177
178         return $this->principalUri;
179
180     }
181
182     /**
183      * Returns a group principal
184      *
185      * This must be a url to a principal, or null if there's no owner
186      *
187      * @return string|null
188      */
189     public function getGroup() {
190
191         return null;
192
193     }
194
195     /**
196      * Returns a list of ACE's for this node.
197      *
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
203      *      be updated.
204      *
205      * @return array
206      */
207     public function getACL() {
208
209         return array(
210             array(
211                 'privilege' => '{DAV:}read',
212                 'principal' => $this->principalUri,
213                 'protected' => true,
214             ),
215             array(
216                 'privilege' => '{DAV:}write',
217                 'principal' => $this->principalUri,
218                 'protected' => true,
219             ),
220
221         );
222
223     }
224
225     /**
226      * Updates the ACL
227      *
228      * This method will receive a list of new ACE's.
229      *
230      * @param array $acl
231      * @return void
232      */
233     public function setACL(array $acl) {
234
235         throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
236
237     }
238
239     /**
240      * Returns the list of supported privileges for this node.
241      *
242      * The returned data structure is a list of nested privileges.
243      * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
244      * standard structure.
245      *
246      * If null is returned from this method, the default privilege set is used,
247      * which is fine for most common usecases.
248      *
249      * @return array|null
250      */
251     public function getSupportedPrivilegeSet() {
252
253         return null;
254
255     }
256
257 }