diff --git a/lib/addressbookprovider.php b/lib/addressbookprovider.php index 21f661cf..46066f55 100644 --- a/lib/addressbookprovider.php +++ b/lib/addressbookprovider.php @@ -116,6 +116,7 @@ class AddressbookProvider implements \OCP\IAddressBook { foreach($ids as $id){ $contact = $this->addressBook->getChild($id); $j = JSONSerializer::serializeContact($contact); + $j['data']['id'] = $id; if (isset($contact->PHOTO)) { $url =\OCP\Util::linkToRoute('contacts_contact_photo', array( @@ -126,7 +127,7 @@ class AddressbookProvider implements \OCP\IAddressBook { $url = \OC_Helper::makeURLAbsolute($url); $j['data']['PHOTO'] = "VALUE=uri:$url"; } - $results[]= $j['data']; + $results[]= $this->convertToSearchResult($j); } } @@ -240,4 +241,29 @@ class AddressbookProvider implements \OCP\IAddressBook { } return VCard::delete($id); } + + /** + * @param $j + * @return array + */ + private function convertToSearchResult($j) { + $data = $j['data']; + $result = array(); + foreach( $data as $key => $d) { + $d = $data[$key]; + if (in_array($key, Properties::$multiProperties)) { + $result[$key] = array_map(function($v){ + return $v['value']; + }, $d); + } else { + if (is_array($d)) { + $result[$key] = $d[0]['value']; + } else { + $result[$key] = $d; + } + } + } + + return $result; + } }