From 0ab26293fa4fb782991354bdc91461760f8eba7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Tue, 12 Apr 2011 23:37:11 +0200 Subject: [PATCH] Allows xnet list sorting by description and members count (Closes #957). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- ChangeLog | 3 +++ modules/xnetlists.php | 34 +++++++++++++++++++++++++++++++++- templates/xnetlists/index.tpl | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29e38c6..d90e2a6 100644 --- 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: diff --git a/modules/xnetlists.php b/modules/xnetlists.php index 8217776..d018754 100644 --- a/modules/xnetlists.php +++ b/modules/xnetlists.php @@ -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()) { diff --git a/templates/xnetlists/index.tpl b/templates/xnetlists/index.tpl index 3bae8b3..f672c20 100644 --- a/templates/xnetlists/index.tpl +++ b/templates/xnetlists/index.tpl @@ -52,11 +52,44 @@ croix verte te permet de t'inscrire, après accord des responsables si l'inscrip - - + + - + {foreach from=$listes item=l} -- 2.1.4
ListeDescription + + {if $order_by eq 'list'} + {if $order eq 'desc'} + + {else} + + {/if} + {/if} + Liste + + + + {if $order_by eq 'desc'} + {if $order eq 'desc'} + + {else} + + {/if} + {/if} + Description + + Diffusion InscriptionNb + + {if $order_by eq 'nbsub'} + {if $order eq 'desc'} + + {else} + + {/if} + {/if} + Nb + +