From: Stéphane Jacob Date: Fri, 21 Oct 2011 08:53:07 +0000 (+0200) Subject: Allows ordering in all NL admin page. X-Git-Tag: xorg/1.1.4~82 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=6327351402ea818866c0edc0b4fa0bc05bd98dcd;p=platal.git Allows ordering in all NL admin page. Signed-off-by: Stéphane Jacob --- diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 67bfc9c..7f1975c 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -105,15 +105,13 @@ class NewsLetter /** Retrieve all newsletters * @return An array of $id => NewsLetter objects */ - public static function getAll() + public static function getAll($sort = 'id', $order = 'ASC') { - $res = XDB::query('SELECT id - FROM newsletters'); - $nls = array(); - foreach ($res->fetchColumn() as $id) { - $nls[$id] = new NewsLetter($id); - } - return $nls; + $res = XDB::fetchAllAssoc('SELECT n.id, g.nom AS group_name, n.name, n.custom_css, n.criteria, g.diminutif AS group_link + FROM newsletters AS n + INNER JOIN groups AS g ON (n.group_id = g.id) + ORDER BY ' . $sort . ' ' . $order); + return $res; } // }}} diff --git a/modules/newsletter.php b/modules/newsletter.php index ff3f749..809caef 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -216,14 +216,36 @@ class NewsletterModule extends PLModule $page->assign('nl_list', $nl->listAllIssues()); } - function handler_admin_nl_groups($page) + function handler_admin_nl_groups($page, $sort = 'id', $order = 'ASC') { require_once 'newsletter.inc.php'; + static $titles = array( + 'id' => 'Id', + 'group_name' => 'Groupe', + 'name' => 'Titre', + 'custom_css' => 'CSS spécifique', + 'criteria' => 'Critères actifs' + ); + static $next_orders = array( + 'ASC' => 'DESC', + 'DESC' => 'ASC' + ); + + if (!array_key_exists($sort, $titles)) { + $sort = 'id'; + } + if (!in_array($order, array('ASC', 'DESC'))) { + $order = 'ASC'; + } + $page->changeTpl('newsletter/admin_all.tpl'); $page->setTitle('Administration - Newsletters : Liste des Newsletters'); - - $page->assign('nls', Newsletter::getAll()); + $page->assign('nls', Newsletter::getAll($sort, $order)); + $page->assign('sort', $sort); + $page->assign('order', $order); + $page->assign('next_order', $next_orders[$order]); + $page->assign('titles', $titles); } function handler_admin_nl_edit($page, $nid = 'last', $aid = null, $action = 'edit') { diff --git a/templates/newsletter/admin_all.tpl b/templates/newsletter/admin_all.tpl index 07af4c0..0e95f00 100644 --- a/templates/newsletter/admin_all.tpl +++ b/templates/newsletter/admin_all.tpl @@ -22,19 +22,30 @@ - - - - - + {foreach from=$titles item=title key=key} + + {/foreach} {foreach from=$nls item=nl} - - - - - + + + + + {/foreach}
IdGroupeTitreCSS spécifiqueCritères actifs + {if $sort eq $key} + + {if $order eq "DESC"} + tri descendant + {else if $order eq "ASC"} + tri ascendant + {/if} + {else} + + {/if} + {$title} + +
{$nl->id}{$nl->group}{$nl->name}{if $nl->hasCustomCss()}Oui{else}Non{/if}{$nl->criteria->flags()}{$nl.id}{$nl.group_name}{$nl.name}{if $nl.custom_css}Oui{else}Non{/if}{$nl.criteria}