ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AddressBook.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CardDAV;
4 
5 use Sabre\DAV;
6 use Sabre\DAVACL;
7 
18 
19  use DAVACL\ACLTrait;
20 
26  protected $addressBookInfo;
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 
119  function createDirectory($name) {
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 }
getChild($name)
Returns a card.
Definition: AddressBook.php:65
getChildACL()
This method returns the ACL&#39;s for card nodes in this address book.
propPatch(DAV\PropPatch $propPatch)
Updates properties on this node.
getSyncToken()
This method returns the current sync-token for this collection.
getProperties($properties)
Returns a list of properties for this nodes.
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&#39;s not valid UTF-8 and attempts to convert it to UTF-8...
Definition: StringUtil.php:79
if($argc< 2) $paths
Definition: migrateto20.php:44
The Card object represents a single Card from an addressbook.
Definition: Card.php:15
AddressBook interface.
createFile($name, $vcardData=null)
Creates a new file.
The AddressBook class represents a CardDAV addressbook, owned by a specific user. ...
Definition: AddressBook.php:17
getChanges($syncToken, $syncLevel, $limit=null)
The getChanges method returns all the changes that have happened, since the specified syncToken and t...
getChildren()
Returns the full list of cards.
Definition: AddressBook.php:78
Collection class.
Definition: Collection.php:15
createDirectory($name)
Creates a new directory.
getMultipleChildren(array $paths)
This method receives a list of paths in it&#39;s first argument.
Definition: AddressBook.php:99
If a class extends ISyncCollection, it supports WebDAV-sync.
ACL-enabled node.
Definition: IACL.php:16
setName($newName)
Renames the addressbook.
__construct(Backend\BackendInterface $carddavBackend, array $addressBookInfo)
Constructor.
Definition: AddressBook.php:41
getOwner()
Returns the owner principal.
IProperties interface.
Definition: IProperties.php:14
$response
getLastModified()
Returns the last modification date as a unix timestamp.
getName()
Returns the name of the addressbook.
Definition: AddressBook.php:53