1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-04 15:24:35 +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){ foreach($ids as $id){
$contact = $this->addressBook->getChild($id); $contact = $this->addressBook->getChild($id);
$j = JSONSerializer::serializeContact($contact); $j = JSONSerializer::serializeContact($contact);
$j['data']['id'] = $id;
if (isset($contact->PHOTO)) { if (isset($contact->PHOTO)) {
$url =\OCP\Util::linkToRoute('contacts_contact_photo', $url =\OCP\Util::linkToRoute('contacts_contact_photo',
array( array(
@ -126,7 +127,7 @@ class AddressbookProvider implements \OCP\IAddressBook {
$url = \OC_Helper::makeURLAbsolute($url); $url = \OC_Helper::makeURLAbsolute($url);
$j['data']['PHOTO'] = "VALUE=uri:$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); 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;
}
} }