Cleverer way to sort users
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 26 Feb 2007 09:00:55 +0000 (09:00 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 26 Feb 2007 09:00:55 +0000 (09:00 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1517 839d8a87-29fc-0310-9880-83ba4fa771e5

modules/lists.php

index 9ae5ce2..0e220ff 100644 (file)
@@ -272,6 +272,17 @@ class ListsModule extends PLModule
         }
     }
 
+    function compare($a, $b)
+    {
+        if ($a['promo'] == $b['promo']) {
+            if ($a['nom'] == $b['nom']) {
+                return strcmp($a['prenom'], $b['prenom']);
+            }
+            return strcmp($a['nom'], $b['nom']);
+        }
+        return $a['promo'] - $b['promo'];
+    }
+
     function _get_list($offset, $limit)
     {
         global $platal;
@@ -292,9 +303,7 @@ class ListsModule extends PLModule
                 $total--;
             }
         }
-        uasort($membres, create_function('$a,$b', 'return $a["promo"] > $b["promo"] || '
-                                                . '($a["promo"] == $b["promo"] && (strcmp($a["nom"], $b["nom"]) > 0 || '
-                                                . '($a["nom"] == $b["nom"] && strcmp($a["prenom"], $b["prenom"]) > 0)));'));
+        uasort($membres, array($this, 'compare'));
         return array($total, $membres);
     }