ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AddressBook.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\DAV;
7
18
19 use DAVACL\ACLTrait;
20
27
33 protected $carddavBackend;
34
41 function __construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo) {
42
43 $this->carddavBackend = $carddavBackend;
44 $this->addressBookInfo = $addressBookInfo;
45
46 }
47
53 function getName() {
54
55 return $this->addressBookInfo['uri'];
56
57 }
58
65 function getChild($name) {
66
67 $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name);
68 if (!$obj) throw new DAV\Exception\NotFound('Card not found');
69 return new Card($this->carddavBackend, $this->addressBookInfo, $obj);
70
71 }
72
78 function getChildren() {
79
80 $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']);
81 $children = [];
82 foreach ($objs as $obj) {
83 $obj['acl'] = $this->getChildACL();
84 $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj);
85 }
86 return $children;
87
88 }
89
99 function getMultipleChildren(array $paths) {
100
101 $objs = $this->carddavBackend->getMultipleCards($this->addressBookInfo['id'], $paths);
102 $children = [];
103 foreach ($objs as $obj) {
104 $obj['acl'] = $this->getChildACL();
105 $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj);
106 }
107 return $children;
108
109 }
110
120
121 throw new DAV\Exception\MethodNotAllowed('Creating collections in addressbooks is not allowed');
122
123 }
124
136 function createFile($name, $vcardData = null) {
137
138 if (is_resource($vcardData)) {
139 $vcardData = stream_get_contents($vcardData);
140 }
141 // Converting to UTF-8, if needed
142 $vcardData = DAV\StringUtil::ensureUTF8($vcardData);
143
144 return $this->carddavBackend->createCard($this->addressBookInfo['id'], $name, $vcardData);
145
146 }
147
153 function delete() {
154
155 $this->carddavBackend->deleteAddressBook($this->addressBookInfo['id']);
156
157 }
158
165 function setName($newName) {
166
167 throw new DAV\Exception\MethodNotAllowed('Renaming addressbooks is not yet supported');
168
169 }
170
176 function getLastModified() {
177
178 return null;
179
180 }
181
194 function propPatch(DAV\PropPatch $propPatch) {
195
196 return $this->carddavBackend->updateAddressBook($this->addressBookInfo['id'], $propPatch);
197
198 }
199
211 function getProperties($properties) {
212
213 $response = [];
214 foreach ($properties as $propertyName) {
215
216 if (isset($this->addressBookInfo[$propertyName])) {
217
218 $response[$propertyName] = $this->addressBookInfo[$propertyName];
219
220 }
221
222 }
223
224 return $response;
225
226 }
227
235 function getOwner() {
236
237 return $this->addressBookInfo['principaluri'];
238
239 }
240
241
249 function getChildACL() {
250
251 return [
252 [
253 'privilege' => '{DAV:}all',
254 'principal' => $this->getOwner(),
255 'protected' => true,
256 ],
257 ];
258
259 }
260
261
271 function getSyncToken() {
272
273 if (
274 $this->carddavBackend instanceof Backend\SyncSupport &&
275 isset($this->addressBookInfo['{DAV:}sync-token'])
276 ) {
277 return $this->addressBookInfo['{DAV:}sync-token'];
278 }
279 if (
280 $this->carddavBackend instanceof Backend\SyncSupport &&
281 isset($this->addressBookInfo['{http://sabredav.org/ns}sync-token'])
282 ) {
283 return $this->addressBookInfo['{http://sabredav.org/ns}sync-token'];
284 }
285
286 }
287
343 function getChanges($syncToken, $syncLevel, $limit = null) {
344
345 if (!$this->carddavBackend instanceof Backend\SyncSupport) {
346 return null;
347 }
348
349 return $this->carddavBackend->getChangesForAddressBook(
350 $this->addressBookInfo['id'],
351 $syncToken,
352 $syncLevel,
353 $limit
354 );
355
356 }
357}
An exception for terminatinating execution or to throw for unit testing.
The AddressBook class represents a CardDAV addressbook, owned by a specific user.
Definition: AddressBook.php:17
createDirectory($name)
Creates a new directory.
getChildren()
Returns the full list of cards.
Definition: AddressBook.php:78
getMultipleChildren(array $paths)
This method receives a list of paths in it's first argument.
Definition: AddressBook.php:99
setName($newName)
Renames the addressbook.
getOwner()
Returns the owner principal.
getSyncToken()
This method returns the current sync-token for this collection.
__construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo)
Constructor.
Definition: AddressBook.php:41
propPatch(DAV\PropPatch $propPatch)
Updates properties on this node.
getChanges($syncToken, $syncLevel, $limit=null)
The getChanges method returns all the changes that have happened, since the specified syncToken and t...
getChildACL()
This method returns the ACL's for card nodes in this address book.
getLastModified()
Returns the last modification date as a unix timestamp.
createFile($name, $vcardData=null)
Creates a new file.
getName()
Returns the name of the addressbook.
Definition: AddressBook.php:53
getProperties($properties)
Returns a list of properties for this nodes.
getChild($name)
Returns a card.
Definition: AddressBook.php:65
The Card object represents a single Card from an addressbook.
Definition: Card.php:15
Collection class.
Definition: Collection.php:15
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
static ensureUTF8($input)
This method takes an input string, checks if it's not valid UTF-8 and attempts to convert it to UTF-8...
Definition: StringUtil.php:79
AddressBook interface.
ACL-enabled node.
Definition: IACL.php:16
IProperties interface.
Definition: IProperties.php:14
If a class extends ISyncCollection, it supports WebDAV-sync.
if($argc< 2) $paths
Definition: migrateto20.php:44
$response