/** 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;
}
// }}}
$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') {
<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>