example: Improve smarty_table_ordered_th function

This commit is contained in:
Benjamin Renard 2023-02-28 20:52:29 +01:00
parent 7f2644b46a
commit 2bf05291fe
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -5,6 +5,8 @@ use EesyPHP\Date;
use EesyPHP\Hook;
use EesyPHP\Log;
use EesyPHP\Tpl;
use EesyPHP\Url;
use function EesyPHP\format_size;
@ -70,14 +72,15 @@ Tpl :: register_function('format_size','smarty_format_size');
function smarty_table_ordered_th($params, $smarty) {
if ($params['order'] && $params['url'] && $params['text'] && is_array($params['search'])) {
$params['url'] .= (strpos($params['url'], '?') === false?'?':'&')."order=".$params['order'];
echo "<a href='".$params['url']."'>".$params['text']."</a>";
$params['url'] = Url::add_url_parameter($params['url'], 'order', $params['order']);
printf("<a href='%s'>%s</a>", $params['url'], $params['text']);
}
if ($params['order'] == $params['search']['order']) {
echo (
' <i class="fa fa-sort-'.
(strtolower($params['search']['order_direction'])=='asc'?'up':'down').
'" aria-hidden="true"></i>');
printf(
' <i class="fa fa-sort-%s" aria-hidden="true"></i>',
strtolower($params['search']['order_direction']) == 'asc'?
'up':'down'
);
}
}
Tpl :: register_function('table_ordered_th','smarty_table_ordered_th');