From 1f61d10d19dc33d19ff34c52ecff120ac663b521 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 27 Feb 2011 23:15:28 +0100 Subject: [PATCH] Main addresses are displayed before secondary addresses (Closes #1401). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- ChangeLog | 1 + classes/address.php | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31bce03..4e44b04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,6 +35,7 @@ Bug/Wish: - #1367: Improves postal address formatting -JAC - #1368: Allows admin profile edition even if birthdate is unknown -JAC - #1369: Properly displays moderated jobs -JAC + - #1401: Main addresses are displayed before secondary addresses -JAC * Register: - #1374: Adapts registration for master and doctorate -JAC diff --git a/classes/address.php b/classes/address.php index 289cfb1..d92ffb9 100644 --- a/classes/address.php +++ b/classes/address.php @@ -809,12 +809,27 @@ class Address return $addresses; } + // Compares two addresses. First sort by publicity, then place primary + // addresses before secondary addresses. + static private function compare(array $a, array $b) + { + $value = ProfileVisibility::comparePublicity($a, $b); + if ($value == 0) { + if ($a['secondary'] != $b['secondary']) { + $value = $a['secondary'] ? 1 : -1; + } + } + return $value; + } + // Formats an array of form addresses into an array of form formatted addresses. static public function formatFormArray(array $data, &$success = true) { + $addresses = self::formArrayWalk($data, 'toFormArray', $success, true); + // Only a single address can be the profile's current address and she must have one. $hasCurrent = false; - foreach ($data as $key => &$address) { + foreach ($addresses as $key => &$address) { if (isset($address['current']) && $address['current']) { if ($hasCurrent) { $address['current'] = false; @@ -830,8 +845,7 @@ class Address } } - $addresses = self::formArrayWalk($data, 'toFormArray', $success, true); - usort($addresses, 'ProfileVisibility::comparePublicity'); + usort($addresses, 'Address::compare'); return $addresses; } -- 2.1.4