summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax/contacts.php
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-06-17 20:11:34 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-06-17 20:25:32 +0200
commit56d25d4d1b5c210b3c48e49d5bd644d09adc1a0b (patch)
treeb93e0fb4f4377c76103bbd6aafe8d312ff051d00 /apps/contacts/ajax/contacts.php
parent92e35bd843890eabeb582c5b616354324f332e85 (diff)
downloadnextcloud-server-56d25d4d1b5c210b3c48e49d5bd644d09adc1a0b.tar.gz
nextcloud-server-56d25d4d1b5c210b3c48e49d5bd644d09adc1a0b.zip
Make the parsing in the controller, not in the template. Assign only relevant entries to the template.
Diffstat (limited to 'apps/contacts/ajax/contacts.php')
-rw-r--r--apps/contacts/ajax/contacts.php37
1 files changed, 20 insertions, 17 deletions
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
index 1edc35709e6..773f027dc64 100644
--- a/apps/contacts/ajax/contacts.php
+++ b/apps/contacts/ajax/contacts.php
@@ -16,29 +16,32 @@ $active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
// Our new array for the contacts sorted by addressbook
$contacts_addressbook = array();
-foreach($contacts_alphabet as $contact):
- if(is_null($contacts_addressbook[$contact['addressbookid']])) {
- $contacts_addressbook[$contact['addressbookid']] = array();
+foreach($contacts_alphabet as $contact) {
+ if(!isset($contacts_addressbook[$contact['addressbookid']])) {
+ $contacts_addressbook[$contact['addressbookid']] = array('contacts' => array());
}
- $contacts_addressbook[$contact['addressbookid']][] = $contact;
-endforeach;
+ $display = trim($contact['fullname']);
+ if(!$display) {
+ $vcard = OC_Contacts_App::getContactVCard($contact['id']);
+ if(!is_null($vcard)) {
+ $struct = OC_Contacts_VCard::structureContact($vcard);
+ $display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]';
+ }
+ }
+ $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display));
+}
-// FIXME: this is kind of ugly - just to replace the keys of the array
-// perhaps we could do some magic combine_array() instead...
-foreach($contacts_addressbook as $addressbook_id => $contacts):
- foreach($active_addressbooks as $addressbook):
+foreach($contacts_addressbook as $addressbook_id => $contacts) {
+ foreach($active_addressbooks as $addressbook) {
if($addressbook_id == $addressbook['id']) {
- unset($contacts_addressbook[$addressbook_id]);
- $contacts_addressbook[$addressbook['displayname']] = $contacts;
+ $contacts_addressbook[$addressbook_id]['displayname'] = $addressbook['displayname'];
}
- endforeach;
-endforeach;
-// This one should be ok for a small amount of Addressbooks
-ksort($contacts_addressbook);
+ }
+}
$tmpl = new OCP\Template("contacts", "part.contacts");
-$tmpl->assign('contacts', $contacts_addressbook, false);
+$tmpl->assign('books', $contacts_addressbook, false);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));
-?>
+