1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-03 15:24:09 +01:00

properly convert the json serialized data to the format as expected by the public contacts search

This commit is contained in:
Thomas Müller 2014-07-30 17:05:09 +02:00 committed by Jan-Christoph Borchardt
parent 23056e8c05
commit 7065c9be05

View File

@ -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;
}
}