]> git.mxchange.org Git - friendica-addons.git/blob - dav/common/dav_user_addressbooks.inc.php
Addon class
[friendica-addons.git] / dav / common / dav_user_addressbooks.inc.php
1 <?php
2
3 /**
4  * The UserCalenders class contains all calendars associated to one user
5  *
6  * @package Sabre
7  * @subpackage CalDAV
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
11  */
12 class Sabre_CardDAV_UserAddressBooksMultiBackend extends Sabre_DAV_Collection implements Sabre_DAV_IExtendedCollection, Sabre_DAVACL_IACL {
13
14         /**
15          * Principal uri
16          *
17          * @var array
18          */
19         protected $principalUri;
20
21         /**
22          * carddavBackend
23          *
24          * @var array|Sabre_CardDAV_Backend_Abstract[]
25          */
26         protected $carddavBackends;
27
28         /**
29          * Constructor
30          *
31          * @param array|Sabre_CardDAV_Backend_Abstract[] $carddavBackends
32          * @param string $principalUri
33          */
34         public function __construct($carddavBackends, $principalUri) {
35
36                 $this->carddavBackends = $carddavBackends;
37                 $this->principalUri = $principalUri;
38
39         }
40
41         /**
42          * Returns the name of this object
43          *
44          * @return string
45          */
46         public function getName() {
47
48                 list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalUri);
49                 return $name;
50
51         }
52
53         /**
54          * Updates the name of this object
55          *
56          * @param string $name
57          * @throws Sabre_DAV_Exception_MethodNotAllowed
58          * @return void
59          */
60         public function setName($name) {
61
62                 throw new Sabre_DAV_Exception_MethodNotAllowed();
63
64         }
65
66         /**
67          * Deletes this object
68          *
69          * @throws Sabre_DAV_Exception_MethodNotAllowed
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          * @throws Sabre_DAV_Exception_MethodNotAllowed
97          * @return null|string|void
98          */
99         public function createFile($filename, $data=null) {
100
101                 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new files in this collection is not supported');
102
103         }
104
105         /**
106          * Creates a new directory under this object.
107          *
108          * This is currently not allowed.
109          *
110          * @param string $filename
111          * @throws Sabre_DAV_Exception_MethodNotAllowed
112          * @return void
113          */
114         public function createDirectory($filename) {
115
116                 throw new Sabre_DAV_Exception_MethodNotAllowed('Creating new collections in this collection is not supported');
117
118         }
119
120         /**
121          * Returns a single calendar, by name
122          *
123          * @param string $name
124          * @throws Sabre_DAV_Exception_NotFound
125          * @todo needs optimizing
126          * @return \Sabre_CardDAV_AddressBook|\Sabre_DAV_INode
127          */
128         public function getChild($name) {
129
130                 foreach($this->getChildren() as $child) {
131                         if ($name==$child->getName())
132                                 return $child;
133
134                 }
135                 throw new Sabre_DAV_Exception_NotFound('Addressbook with name \'' . $name . '\' could not be found');
136
137         }
138
139         /**
140          * Returns a list of addressbooks
141          *
142          * @return array|Sabre_DAV_INode[]
143          */
144         public function getChildren() {
145
146                 $objs = array();
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);
151                         }
152                 }
153                 return $objs;
154
155         }
156
157         /**
158          * Creates a new addressbook
159          *
160          * @param string $name
161          * @param array $resourceType
162          * @param array $properties
163          * @throws Sabre_DAV_Exception_InvalidResourceType
164          * @return void
165          */
166         public function createExtendedCollection($name, array $resourceType, array $properties) {
167
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');
170                 }
171                 $this->carddavBackends[0]->createAddressBook($this->principalUri, $name, $properties);
172
173         }
174
175         /**
176          * Returns the owner principal
177          *
178          * This must be a url to a principal, or null if there's no owner
179          *
180          * @return string|null
181          */
182         public function getOwner() {
183
184                 return $this->principalUri;
185
186         }
187
188         /**
189          * Returns a group principal
190          *
191          * This must be a url to a principal, or null if there's no owner
192          *
193          * @return string|null
194          */
195         public function getGroup() {
196
197                 return null;
198
199         }
200
201         /**
202          * Returns a list of ACE's for this node.
203          *
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
209          *      be updated.
210          *
211          * @return array
212          */
213         public function getACL() {
214
215                 return array(
216                         array(
217                                 'privilege' => '{DAV:}read',
218                                 'principal' => $this->principalUri,
219                                 'protected' => true,
220                         ),
221                         array(
222                                 'privilege' => '{DAV:}write',
223                                 'principal' => $this->principalUri,
224                                 'protected' => true,
225                         ),
226
227                 );
228
229         }
230
231         /**
232          * Updates the ACL
233          *
234          * This method will receive a list of new ACE's.
235          *
236          * @param array $acl
237          * @throws Sabre_DAV_Exception_MethodNotAllowed
238          * @return void
239          */
240         public function setACL(array $acl) {
241
242                 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
243
244         }
245
246         /**
247          * Returns the list of supported privileges for this node.
248          *
249          * The returned data structure is a list of nested privileges.
250          * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
251          * standard structure.
252          *
253          * If null is returned from this method, the default privilege set is used,
254          * which is fine for most common usecases.
255          *
256          * @return array|null
257          */
258         public function getSupportedPrivilegeSet() {
259
260                 return null;
261
262         }
263
264 }