Skip to content

Commit

Permalink
Merge pull request #6018 from christianbeeznest/C1-22330
Browse files Browse the repository at this point in the history
Session: Add dynamic sorting for users table by name and date - refs BT#22330
  • Loading branch information
christianbeeznest authored Jan 7, 2025
2 parents 135e61e + 8f51bd8 commit 580b90a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions main/session/resume_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,32 @@
$userList = SessionManager::get_users_by_session($sessionId);

if (!empty($userList)) {
$sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : null;
$sortColumn = isset($_GET['sort']) ? Security::remove_XSS($_GET['sort']) : 'registration_date';
$sortOrder = isset($_GET['order']) && Security::remove_XSS($_GET['order']) === 'ASC' ? SORT_ASC : SORT_DESC;

$allowedColumns = ['user', 'registration_date'];
if (!in_array($sortColumn, $allowedColumns, true)) {
$sortColumn = 'registration_date';
}

usort($userList, function ($a, $b) use ($sortColumn, $sortOrder) {
if ($sortColumn === 'user') {
$valueA = strtolower(api_get_user_info($a['user_id'])['complete_name_with_username']);
$valueB = strtolower(api_get_user_info($b['user_id'])['complete_name_with_username']);
} else {
$valueA = strtotime($a['registered_at']);
$valueB = strtotime($b['registered_at']);
}
return $sortOrder === SORT_ASC ? $valueA <=> $valueB : $valueB <=> $valueA;
});

$table = new HTML_Table(
['class' => 'table table-hover table-striped data_table', 'id' => 'session-user-list']
);
$table->setHeaderContents(0, 0, get_lang('User'));
$table->setHeaderContents(0, 0, '<a href="?id_session='.$sessionId.'&sort=user&order='.($sortColumn === 'user' && $sortOrder === SORT_ASC ? 'DESC' : 'ASC').'">'.get_lang('User').'</a>');
$table->setHeaderContents(0, 1, get_lang('Status'));
$table->setHeaderContents(0, 2, get_lang('RegistrationDate'));
$table->setHeaderContents(0, 2, '<a href="?id_session='.$sessionId.'&sort=registration_date&order='.($sortColumn === 'registration_date' && $sortOrder === SORT_ASC ? 'DESC' : 'ASC').'">'.get_lang('RegistrationDate').'</a>');
$table->setHeaderContents(0, 3, get_lang('Actions'));

$row = 1;
Expand Down

0 comments on commit 580b90a

Please sign in to comment.