Allows xnet list sorting by description and members count (Closes #957).
authorStéphane Jacob <sj@m4x.org>
Tue, 12 Apr 2011 21:37:11 +0000 (23:37 +0200)
committerStéphane Jacob <sj@m4x.org>
Wed, 13 Apr 2011 08:10:10 +0000 (10:10 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
modules/xnetlists.php
templates/xnetlists/index.tpl

index 29e38c6..d90e2a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@ Bug/Wish:
     * Profile:
         - #1445: Add job entry year                                        -JAC
 
+    * XnetList:
+        - #957: Allows xnet list sorting by description and members count  -JAC
+
 From 1.1.0 branch:
 
     * Search:
index 8217776..d018754 100644 (file)
@@ -70,7 +70,7 @@ class XnetListsModule extends ListsModule
         return $globals->asso('mail_domain');
     }
 
-    function handler_lists($page)
+    function handler_lists($page, $order_by = null, $order = null)
     {
         global $globals;
         require_once 'emails.inc.php';
@@ -102,7 +102,39 @@ class XnetListsModule extends ListsModule
         }
 
         $listes = $this->client->get_lists();
+        // Default ordering is by ascending names.
+        if (is_null($order_by) || is_null($order)
+            || !in_array($order_by, array('list', 'desc', 'nbsub'))
+            || !in_array($order, array('asc', 'desc'))) {
+            $order_by = 'list';
+            $order = 'asc';
+        }
+
+        $compare = function ($a, $b) use ($order_by, $order)
+        {
+            switch ($order_by) {
+              case 'desc':
+                $a[$order_by] = replace_accent($a[$order_by]);
+                $b[$order_by] = replace_accent($b[$order_by]);
+              case 'list':
+                $res = strcasecmp($a[$order_by], $b[$order_by]);
+                break;
+              case 'nbsub':
+                $res = $a[$order_by] - $b[$order_by];
+                break;
+              default:
+                $res = 0;
+            }
+
+            if ($order == 'asc') {
+                return $res;
+            }
+            return $res * -1;
+        };
+        usort($listes, $compare);
         $page->assign('listes', $listes);
+        $page->assign('order_by', $order_by);
+        $page->assign('order', $order);
         $page->assign('aliases', iterate_list_alias($globals->asso('mail_domain')));
         $page->assign('may_update', may_update());
         if (S::suid()) {
index 3bae8b3..f672c20 100644 (file)
@@ -52,11 +52,44 @@ croix verte te permet de t'inscrire, après accord des responsables si l'inscrip
 
 <table cellpadding="0" cellspacing="0" class='large'>
   <tr>
-    <th colspan="2">Liste</th>
-    <th>Description</th>
+    <th colspan="2">
+      <a href="{$platal->ns}lists/list/{if $order_by eq 'list' && $order eq 'asc'}desc{else}asc{/if}">
+        {if $order_by eq 'list'}
+        {if $order eq 'desc'}
+          <img src="{$platal->baseurl}images/up.png" alt="" title="Tri décroissant" />
+        {else}
+          <img src="{$platal->baseurl}images/dn.png" alt="" title="Tri croissant" />
+        {/if}
+        {/if}
+        Liste
+      </a>
+    </th>
+    <th>
+      <a href="{$platal->ns}lists/desc/{if $order_by eq 'desc' && $order eq 'asc'}desc{else}asc{/if}">
+        {if $order_by eq 'desc'}
+        {if $order eq 'desc'}
+          <img src="{$platal->baseurl}images/up.png" alt="" title="Tri décroissant" />
+        {else}
+          <img src="{$platal->baseurl}images/dn.png" alt="" title="Tri croissant" />
+        {/if}
+        {/if}
+        Description
+      </a>
+    </th>
     <th>Diffusion</th>
     <th>Inscription</th>
-    <th>Nb</th>
+    <th>
+      <a href="{$platal->ns}lists/nbsub/{if $order_by eq 'nbsub' && $order eq 'asc'}desc{else}asc{/if}">
+        {if $order_by eq 'nbsub'}
+        {if $order eq 'desc'}
+          <img src="{$platal->baseurl}images/up.png" alt="" title="Tri décroissant" />
+        {else}
+          <img src="{$platal->baseurl}images/dn.png" alt="" title="Tri croissant" />
+        {/if}
+        {/if}
+        Nb
+      </a>
+    </th>
     <th>&nbsp;</th>
   </tr>
   {foreach from=$listes item=l}