GenericTable: refactor order and pagination initalisation

This commit is contained in:
2024-12-19 15:00:00 +01:00
parent 06c95853f5
commit bb8a8bad27
6 changed files with 85 additions and 118 deletions

View File

@@ -90,19 +90,20 @@ class ManageUsers extends HTMLController
],
],
],
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
'default_sort_order' => 'id_user',
'default_sort_direction' => 'down',
'start' => $_GET['start'] ?? 0,
'sort_order' => $_GET['order'] ?? '',
'sort_direction' => $_GET['dir'] ?? '',
'title' => 'Manage users',
'no_items_label' => 'No users meet the requirements of the current filter.',
'items_per_page' => 30,
'index_class' => 'col-md-6',
'base_url' => BASEURL . '/manageusers/',
'get_data' => function($offset = 0, $limit = 30, $order = '', $direction = 'down') {
if (!in_array($order, ['id_user', 'surname', 'first_name', 'slug', 'emailaddress', 'last_action_time', 'ip_address', 'is_admin']))
$order = 'id_user';
'get_data' => function($offset, $limit, $order, $direction) {
assert(in_array($order, ['id_user', 'surname', 'first_name', 'slug', 'emailaddress', 'last_action_time', 'ip_address', 'is_admin']));
$data = Registry::get('db')->queryAssocs('
return Registry::get('db')->queryAssocs('
SELECT *
FROM users
ORDER BY {raw:order}
@@ -112,18 +113,8 @@ class ManageUsers extends HTMLController
'offset' => $offset,
'limit' => $limit,
]);
return [
'rows' => $data,
'order' => $order,
'direction' => $direction,
];
},
'get_count' => function() {
return Registry::get('db')->queryValue('
SELECT COUNT(*)
FROM users');
}
'get_count' => 'Member::getCount',
];
$table = new GenericTable($options);