admin/emails/broken: Sort lines of the produced CSV
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Wed, 9 Apr 2014 20:56:16 +0000 (22:56 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Wed, 9 Apr 2014 21:06:54 +0000 (23:06 +0200)
Sort these lines by (promo, sortname) instead of email address.

modules/email.php

index 360c462..f6ad6b2 100644 (file)
@@ -907,6 +907,14 @@ class EmailModule extends PLModule
                                WHERE  flags = \'active\' AND broken_level = 1
                                       AND DATE_ADD(last, INTERVAL 1 YEAR) < CURDATE()');
 
+                // Sort $broken_user_list with (promo, sortname, pid)
+                $sortable_array = array();
+                foreach ($broken_user_list as $pid => $mails) {
+                    $profile = $broken_user_profiles[$pid];
+                    $sortable_array[$pid] = array($profile->promo(), $profile->sortName(), $pid);
+                }
+                asort($sortable_array);
+
                 // Output the list of users with recently broken addresses,
                 // along with the count of valid redirections.
                 pl_cached_content_headers('text/x-csv', 1);
@@ -914,7 +922,8 @@ class EmailModule extends PLModule
                 $csv = fopen('php://output', 'w');
                 fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';');
                 $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
-                foreach ($broken_user_list as $pid => $mails) {
+                foreach (array_keys($sortable_array) as $pid) {
+                    $mails = $broken_user_list[$pid];
                     $profile = $broken_user_profiles[$pid];
                     $current_corps = $profile->getCorpsName();
                     $jobs = $profile->getJobs();