Try to detect real, current location of users in minifiche.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 21 Oct 2010 19:52:29 +0000 (21:52 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 21 Oct 2010 19:53:53 +0000 (21:53 +0200)
Previous behaviour for 'getMainAddress' was to fetch the first among all
current/home addresses, even if that address was a secondary / temporary
address.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php

index 304ca7b..8eb66bb 100644 (file)
@@ -538,11 +538,15 @@ class Profile
 
     public function getMainAddress()
     {
-        $addr = $this->getAddresses(self::ADDRESS_PERSO | self::ADDRESS_MAIN);
-        if (count($addr) == 0) {
-            return null;
+        $main = $this->getAddresses(self::ADDRESS_MAIN);
+        $perso = $this->getAddresses(self::ADDRESS_PERSO);
+
+        if (count($main)) {
+            return array_pop($main);
+        } else if (count($perso)) {
+            return array_pop($perso);
         } else {
-            return array_pop($addr);
+            return null;
         }
     }