From 03f9741a616a4413e46e18ec6e48f2a5ae3936b7 Mon Sep 17 00:00:00 2001 From: "Aleksander Machniak (Kolab Systems)" Date: Thu, 28 Jul 2011 12:00:11 +0200 Subject: [PATCH] Fix contacts sorting when there's no name field --- .../lib/rcube_kolab_contacts.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index da087df8..d62a7f3b 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -982,7 +982,25 @@ class rcube_kolab_contacts extends rcube_addressbook */ private function _sort_contacts_comp($a, $b) { - return strcasecmp($a['name'], $b['name']); + $a_name = $a['name']; + $b_name = $b['name']; + + if (!$a_name) { + $a_name = join(' ', array_filter(array($a['prefix'], $a['firstname'], + $a['middlename'], $a['surname'], $a['suffix']))); + if (!$a_name) { + $a_name = is_array($a['email']) ? $a['email'][0] : $a['email']; + } + } + if (!$b_name) { + $b_name = join(' ', array_filter(array($b['prefix'], $b['firstname'], + $b['middlename'], $b['surname'], $b['suffix']))); + if (!$b_name) { + $b_name = is_array($b['email']) ? $b['email'][0] : $b['email']; + } + } + + return strcasecmp($a_name, $b_name); } /**