cardMgr = $cardMgr; } public function getAddressBooksForUser ($principalUri) { $addressBooks = []; foreach ($this->cardMgr->getCollections($principalUri) as $row) { $addressBooks[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{DAV:}displayname' => $row['displayname'], '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'], '{http://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'], ]; } return $addressBooks; } public function updateAddressBook ($addressBookId, \Sabre\DAV\PropPatch $propPatch) { $supportedProperties = [ '{DAV:}displayname', '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description', ]; $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { $values = []; foreach ($mutations as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $values['displayname'] = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $values['description'] = $newValue; break; } } $this->cardMgr->updateCollection($addressBookId, $values); return true; }); } public function createAddressBook ($principalUri, $url, array $properties) { $displayname = null; $description = null; foreach ($properties as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $displayname = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $description = $newValue; break; default: throw new DAV\Exception\BadRequest('Unknown property: '.$property); } } return $this->cardMgr->createCollection($principalUri, $url, $displayname, $description); } public function deleteAddressBook ($addressBookId) { $this->cardMgr->deleteCollection($addressBookId); } public function getCards ($addressbookId) { $objects = $this->cardMgr->getObjects($addressbookId); foreach ($objects as $key => $object) { $objects[$key]['etag'] = '"'.$object['etag'].'"'; } return $objects; } public function getCard ($addressBookId, $cardUri) { $object = $this->cardMgr->getObject($addressBookId, $cardUri); if (isset($object['etag'])) $object['etag'] = '"'.$object['etag'].'"'; return $object; } public function getMultipleCards ($addressBookId, array $uris) { $result = []; foreach ($uris as $uri) { $result[] = $this->getCard($addressBookId, $uri); } return $result; } public function createCard ($addressBookId, $uri, $cardData) { $etag = $this->cardMgr->createObject($addressBookId, $uri, $cardData); return '"'.$etag.'"'; } public function updateCard ($addressBookId, $uri, $cardData) { $etag = $this->cardMgr->updateObject($addressBookId, $uri, $cardData); return '"'.$etag.'"'; } public function deleteCard ($addressBookId, $uri) { return $this->cardMgr->deleteObject($addressBookId, $uri); } public function getChangesForAddressBook ($addressBookId, $syncToken, $syncLevel, $limit = null) { return $this->cardMgr->getChanges($addressBookId, $syncToken, $syncLevel); } }