diff options
author | Stephan Bergemann <st.bergemann@htw-berlin.de> | 2012-06-17 02:29:35 +0200 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-06-17 20:25:32 +0200 |
commit | 92e35bd843890eabeb582c5b616354324f332e85 (patch) | |
tree | 75ef31aa9e2810ae3afc61312bd197de86168d3c /apps/contacts/ajax | |
parent | 7f485d1b2058a1af2f82555939df3d6c306047a3 (diff) | |
download | nextcloud-server-92e35bd843890eabeb582c5b616354324f332e85.tar.gz nextcloud-server-92e35bd843890eabeb582c5b616354324f332e85.zip |
now a little less in template - more in ajax controller
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r-- | apps/contacts/ajax/contacts.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php index dbc9be5ca56..1edc35709e6 100644 --- a/apps/contacts/ajax/contacts.php +++ b/apps/contacts/ajax/contacts.php @@ -11,9 +11,33 @@ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser()); -$contacts = OC_Contacts_VCard::all($ids); +$contacts_alphabet = OC_Contacts_VCard::all($ids); +$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(); + } + $contacts_addressbook[$contact['addressbookid']][] = $contact; +endforeach; + +// 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): + if($addressbook_id == $addressbook['id']) { + unset($contacts_addressbook[$addressbook_id]); + $contacts_addressbook[$addressbook['displayname']] = $contacts; + } + 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, false); +$tmpl->assign('contacts', $contacts_addressbook, false); $page = $tmpl->fetchPage(); OCP\JSON::success(array('data' => array( 'page' => $page ))); |