Allows ordering in all NL admin page.
authorStéphane Jacob <sj@m4x.org>
Fri, 21 Oct 2011 08:53:07 +0000 (10:53 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 21 Oct 2011 08:53:07 +0000 (10:53 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/newsletter.inc.php
modules/newsletter.php
templates/newsletter/admin_all.tpl

index 67bfc9c..7f1975c 100644 (file)
@@ -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;
     }
 
     // }}}
index ff3f749..809caef 100644 (file)
@@ -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') {
index 07af4c0..0e95f00 100644 (file)
 
 <table class="bicol" cellpadding="3" cellspacing="0" summary="Liste des Newsletter actives">
   <tr>
-    <th>Id</th>
-    <th>Groupe</th>
-    <th>Titre</th>
-    <th>CSS spécifique</th>
-    <th>Critères actifs</th>
+    {foreach from=$titles item=title key=key}
+    <th>
+      {if $sort eq $key}
+      <a href="admin/nls/{$key}/{$next_order}">
+      {if $order eq "DESC"}
+      <img src="images/dn.png" alt="tri descendant" />
+      {else if $order eq "ASC"}
+      <img src="images/up.png" alt="tri ascendant" />
+      {/if}
+      {else}
+      <a href="admin/nls/{$key}">
+      {/if}
+      {$title}
+      </a>
+    </th>
+    {/foreach}
   </tr>
   {foreach from=$nls item=nl}
   <tr class="{cycle values="pair,impair"}">
-    <td class="titre">{$nl->id}</td>
-    <td>{$nl->group}</td>
-    <td><a href="http://www.polytechnique.net/{$nl->group}/admin/nl">{$nl->name}</a></td>
-    <td>{if $nl->hasCustomCss()}Oui{else}Non{/if}</td>
-    <td>{$nl->criteria->flags()}</td>
+    <td class="titre">{$nl.id}</td>
+    <td>{$nl.group_name}</td>
+    <td><a href="http://www.polytechnique.net/{$nl.group_link}/admin/nl">{$nl.name}</a></td>
+    <td>{if $nl.custom_css}Oui{else}Non{/if}</td>
+    <td>{$nl.criteria}</td>
   </tr>
   {/foreach}
 </table>