From: Stéphane Jacob Date: Sun, 27 Feb 2011 22:15:28 +0000 (+0100) Subject: Main addresses are displayed before secondary addresses (Closes #1401). X-Git-Tag: xorg/1.1.0~120 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=1f61d10d19dc33d19ff34c52ecff120ac663b521;p=platal.git Main addresses are displayed before secondary addresses (Closes #1401). Signed-off-by: Stéphane Jacob --- 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; }