From fb95e6e19da997bf48170f5fbc55b35e1792a570 Mon Sep 17 00:00:00 2001 From: Julian Prud'homme Date: Fri, 6 Apr 2007 10:56:33 +0200 Subject: [PATCH] [svn r11897] Allow the table sort --- main/mySpace/index.php | 35 +++++++++++++++++++++++++++++++++-- main/mySpace/student.php | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 8d28950db6..0eab9c119a 100644 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -53,7 +53,14 @@ function count_coaches() return $total_no_coachs; } - +function sort_users($a, $b) +{ + global $tracking_column; + if($a[$tracking_column] > $b[$tracking_column]) + return 1; + else + return -1; +} /************************** * MAIN CODE @@ -424,6 +431,8 @@ if(api_is_allowed_to_create_course() && $view=='teacher') $table = new SortableTable('tracking_list_course', 'count_teacher_courses'); + $parameters['view'] = 'teacher'; + $table->set_additional_parameters($parameters); $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"'); $table -> set_header(1, get_lang('NbStudents'), false); $table -> set_header(2, get_lang('TimeSpentInTheCourse'), false); @@ -533,7 +542,12 @@ if(api_is_allowed_to_create_course() && $view=='teacher') if(api_is_platform_admin() && $view=='admin'){ + $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : 0; + $tracking_direction = isset($_GET['tracking_list_coaches_direction']) ? $_GET['tracking_list_coaches_direction'] : DESC; + $table = new SortableTable('tracking_list_coaches', 'count_coaches'); + $parameters['view'] = 'admin'; + $table->set_additional_parameters($parameters); $table -> set_header(0, get_lang('FirstName'), true, 'align="center"'); $table -> set_header(1, get_lang('LastName'), true, 'align="center"'); $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false); @@ -562,6 +576,8 @@ if(api_is_platform_admin() && $view=='admin'){ $result_coaches=api_sql_query($sqlCoachs, __FILE__, __LINE__); $total_no_coachs = mysql_num_rows($result_coaches); + $all_datas=array(); + while($a_coachs=mysql_fetch_array($result_coaches)){ $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($a_coachs['user_id'])); @@ -579,7 +595,7 @@ if(api_is_platform_admin() && $view=='admin'){ $table_row[] = $nb_courses; $table_row[] = $nb_sessions; $table_row[] = ''; - $table -> addRow($table_row, 'align="right"'); + $all_datas[] = $table_row; $csv_content[] = array( $a_coachs['firstname'], @@ -591,6 +607,21 @@ if(api_is_platform_admin() && $view=='admin'){ ); } + + usort($all_datas, 'sort_users'); + if($tracking_direction == 'ASC') + rsort($all_datas); + + if($export_csv) + { + usort($csv_content, 'sort_users'); + } + + foreach($all_datas as $row) + { + $table -> addRow($row,'align="right"'); + } + $table -> updateColAttributes(0,array('align'=>'left')); $table -> updateColAttributes(1,array('align'=>'left')); $table -> updateColAttributes(3,array('align'=>'left')); diff --git a/main/mySpace/student.php b/main/mySpace/student.php index 4c5d2e227e..f06b13cc4f 100644 --- a/main/mySpace/student.php +++ b/main/mySpace/student.php @@ -112,7 +112,7 @@ if($isCoach || api_is_platform_admin()) $table -> set_header(4, get_lang('Score'),false); $table -> set_header(5, get_lang('Student_publication'),false); $table -> set_header(6, get_lang('Messages'),false); - $table -> set_header(7, get_lang('LatestLogin'), 'align="center'); + $table -> set_header(7, get_lang('LatestLogin'), false); $table -> set_header(8, get_lang('Details'),false); if($export_csv)