From 6d80a3d4dc78f1aa2f7a0e6ab1785ac67d4555cc Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 25 Feb 2014 13:05:02 +0100 Subject: [PATCH] Simplifying reports see BT#7297 --- main/inc/lib/tracking.lib.php | 426 +++++++++----- main/mySpace/index.php | 1034 ++++++--------------------------- 2 files changed, 431 insertions(+), 1029 deletions(-) diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 051a877a8a..3b64ce3f05 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -24,18 +24,28 @@ class Tracking { /** * Calculates the time spent on the platform by a user - * @param int User id + * @param int|array User id * @param string type of time filter: 'last_week' or 'custom' * @param strgin start date date('Y-m-d H:i:s') * @param strgin end date date('Y-m-d H:i:s') * @return timestamp $nb_seconds */ - public static function get_time_spent_on_the_platform($user_id, $time_filter = 'last_7_days', $start_date = null, $end_date = null) - { - $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - + public static function get_time_spent_on_the_platform( + $user_id, + $time_filter = 'last_7_days', + $start_date = null, + $end_date = null + ) { + $tbl_track_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); $condition_time = ''; + if (is_array($user_id)) { + $userList = array_map('intval', $user_id); + $userCondition = " login_user_id IN ('".implode("','", $userList)."')"; + } else { + $userCondition = " login_user_id = ".intval($user_id); + } + if (empty($time_filter)) { $time_filter = 'last_week'; } @@ -54,47 +64,24 @@ class Tracking $condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") '; break; case 'custom': - if (!empty($start_date) && !empty($end_date)) { + if (!empty($start_date) && !empty($end_date)) { $condition_time = ' AND (login_date >= "'.$start_date.'" AND logout_date <= "'.$end_date.'" ) '; } break; } - $sql = 'SELECT login_date, logout_date FROM '.$tbl_track_login.' - WHERE login_user_id = '.intval($user_id).$condition_time; + $sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff + FROM '.$tbl_track_login.' + WHERE '.$userCondition.$condition_time; $rs = Database::query($sql); + $row = Database::fetch_array($rs, 'ASSOC'); + $diff = $row['diff']; - $nb_seconds = 0; - - $wrong_logout_dates = false; - - while ($a_connections = Database::fetch_array($rs)) { - - $s_login_date = $a_connections["login_date"]; - $s_logout_date = $a_connections["logout_date"]; - - $i_timestamp_login_date = strtotime($s_login_date); - $i_timestamp_logout_date = strtotime($s_logout_date); - - if ($i_timestamp_logout_date > 0) { - // @TODO YW 20110708: for some reason the result here is often - // negative, resulting in a negative time total. Considering the - // logout_date is > 0, this can only mean that the database - // contains items where the login_date is higher (=later) than - // the logout date for a specific connexion. This has to be - // analyzed and fixed. Also see the get_time_spent_on_the_course - // for SQL summing. - $nb_seconds += abs($i_timestamp_logout_date - $i_timestamp_login_date); - } else { // there are wrong datas in db, then we can't give a wrong time - $wrong_logout_dates = true; - } - } - - if($nb_seconds>0 || !$wrong_logout_dates) { - return $nb_seconds; - } else { - return -1; //-1 means we have wrong datas in the db - } + if ($diff >= 0) { + return $diff; + } else { + return -1; + } } /** @@ -106,13 +93,10 @@ class Tracking */ public static function get_time_spent_on_the_course($user_id, $course_code, $session_id = 0) { - // protect datas $course_code = Database::escape_string($course_code); $session_id = intval($session_id); $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - - $condition_user = ""; if (is_array($user_id)) { $user_id = array_map('intval', $user_id); $condition_user = " AND user_id IN (".implode(',',$user_id).") "; @@ -122,7 +106,9 @@ class Tracking } $sql = "SELECT - SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds + SUM ( + UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date) + ) as nb_seconds FROM $tbl_track_course WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) AND @@ -155,7 +141,6 @@ class Tracking return false; } - /** * Get las connection date for a student * @param int Student id @@ -198,6 +183,44 @@ class Tracking return false; } + /** + * Get las connection date for a student + * @param array Student id array + * @param int $days + * @param bool $getCount + * @return int + */ + public static function getInactiveUsers($studentList, $days, $getCount = true) + { + if (empty($studentList)) { + return 0; + } + $days = intval($days); + $date = api_get_utc_datetime(strtotime($days.' days ago')); + $studentList = array_map('intval', $studentList); + + $tbl_track_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $select = " SELECT login_user_id "; + if ($getCount) { + $select = " SELECT count(DISTINCT login_user_id) as count"; + } + $sql = "$select + FROM $tbl_track_login + WHERE + login_user_id IN (' ". implode("','", $studentList) . "' ) AND + login_date < '$date' + "; + $rs = Database::query($sql); + if (Database::num_rows($rs) > 0) { + if ($getCount) { + $count = Database::fetch_array($rs); + return $count['count']; + } + return Database::store_result($rs, 'ASSOC'); + } + return false; + } + /** * Get first user's connection date on the course * @param int User id @@ -555,69 +578,60 @@ class Tracking * @param bool Will return an array of the type: [sum_of_progresses, number] if it is set to true * @return double Average progress of the user in this course */ - public static function get_avg_student_progress($student_id, $course_code, $lp_ids = array(), $session_id = null, $return_array = false) + public static function get_avg_student_progress($student_id, $course_code = null, $lp_ids = array(), $session_id = null, $return_array = false) { + $conditions = array(); // Get the information of the course. $course_info = api_get_course_info($course_code); if (!empty($course_info)) { - // table definition - $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW); - $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN); + $conditions[] = " c_id = {$course_info['real_id']} "; + } + // table definition + $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW); - // Compose a filter based on optional learning paths list given - $condition_lp = ""; + // Compose a filter based on optional learning paths list given + $condition_lp = null; + if (!empty($lp_ids)) { + if (count($lp_ids) > 0) { + $lp_ids = array_map('intval', $lp_ids); + $conditions[] = " lp_view.lp_id IN(".implode(',', $lp_ids).") "; + } + } - if (!empty($lp_ids)) { - if (count($lp_ids) > 0) { - $condition_lp =" AND id IN(".implode(',',$lp_ids).") "; - } - } - $session_id = intval($session_id); - $sql = "SELECT id FROM $tbl_course_lp lp WHERE c_id = {$course_info['real_id']} $condition_lp"; - $res_count_lp = Database::query($sql); - - // count the number of learning paths - $lp_id = array(); - while ($row_lp = Database::fetch_array($res_count_lp,'ASSOC')) { - $lp_id[] = $row_lp['id']; + // If there is at least one learning path and one student. + if (!empty($student_id)) { + if (is_array($student_id)) { + $student_id = array_map('intval', $student_id); + $conditions[] = " lp_view.user_id IN (".implode(',', $student_id).") "; + } else { + $student_id = intval($student_id); + $conditions[] = " lp_view.user_id = '$student_id' "; } - $count_lp = count($lp_id); - // If there is at least one learning path and one student. - if ($count_lp>0 && !empty($student_id)) { - if (is_array($student_id)) { - array_walk($student_id,'intval'); - $condition_user = " lp_view.user_id IN (".implode(',',$student_id).") AND "; - } else { - $student_id = intval($student_id); - $condition_user = " lp_view.user_id = '$student_id' AND "; - } - // Get last view for each student (in case of multi-attempt) - // Also filter on LPs of this session - $sql_maxes = "SELECT MAX(view_count), progress FROM $tbl_course_lp_view lp_view - WHERE c_id = {$course_info['real_id']} AND - $condition_user session_id = $session_id AND - lp_view.lp_id IN (".implode(',',$lp_id).") - GROUP BY lp_id, user_id"; - $res_maxes = Database::query($sql_maxes); - $sum = 0; - while ($row_maxes = Database::fetch_array($res_maxes)) { - $sum += $row_maxes[1]; - } - // average progress = total sum divided by the number of views - // summed up. - $number_items = count($lp_id); - if ($number_items == 0) { - return 0; //not necessary to return something else if there is no view - } - if (!$return_array) { - $avg_progress = round($sum / $number_items, 1); - return $avg_progress; - } else { - return array($sum, $number_items); - } + if (!empty($session_id)) { + $conditions[] = " session_id = $session_id "; + } + $conditionToString = implode('AND', $conditions); + + // Get last view for each student (in case of multi-attempt) + // Also filter on LPs of this session + $sql = " SELECT + MAX(view_count), + AVG(progress) average, + SUM(progress) sum_progress, + count(progress) count_progress + FROM $tbl_course_lp_view lp_view + WHERE + $conditionToString + GROUP BY lp_id"; + $result = Database::query($sql); + $row = Database::fetch_array($result, 'ASSOC'); + if (!$return_array) { + $avg_progress = round($row['average'], 1); + return $avg_progress; + } else { + return array($row['sum_progress'], $row['count_progress']); } } - return null; } /** @@ -946,6 +960,89 @@ class Tracking return null; } + /** + * This function gets: + * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max scores. + * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max scores. + * 3. And finally it will return the average between 1. and 2. + * This function does not take the results of a Test out of a LP + * + * @param int|array Array of user ids or an user id + * @param string Course code + * @param array List of LP ids + * @param int Session id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered + * @param bool Returns an array of the type [sum_score, num_score] if set to true + * @param bool get only the latest attempts or ALL attempts + * @return string Value (number %) Which represents a round integer explain in got in 3. + */ + public static function getAverageStudentScore( + $student_id, + $course_code = null, + $lp_ids = array(), + $session_id = null + ) { + $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + + if (empty($student_id)) { + return 0; + } + + $conditions = array(); + + if (!empty($course_code)) { + $course = api_get_course_info($course_code); + $course_id = $course['real_id']; + $conditions[] = " c_id = {$course['real_id']}"; + } + + // get course tables names + $tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION); + $lp_table = Database :: get_course_table(TABLE_LP_MAIN); + $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM); + $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW); + $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW); + + // Compose a filter based on optional learning paths list given + + if (!empty($lp_ids) && count($lp_ids) > 0) { + $conditions[] = " id IN(".implode(',', $lp_ids).") "; + } + + // Compose a filter based on optional session id + $session_id = intval($session_id); + if (!empty($session_id)) { + $conditions[] = " session_id = $session_id "; + } + + if (is_array($student_id)) { + array_walk($student_id, 'intval'); + $conditions[] =" lp_view.user_id IN (".implode(',', $student_id).") "; + } else { + $conditions[] =" lp_view.user_id = $student_id "; + } + + $conditionsToString = implode('AND ', $conditions); + //lp_iv.max_score as max_score_item_view, + $sql = "SELECT SUM(lp_iv.score) sum_score, + SUM(lp_i.max_score) sum_max_score, + count(*) as count + FROM $lp_item_view_table as lp_iv + INNER JOIN $lp_item_table as lp_i + ON lp_i.id = lp_iv.lp_item_id + INNER JOIN $lp_table as lp + ON lp.id = lp_i.lp_id + INNER JOIN $lp_view_table as lp_view + ON (lp_view.lp_id = lp.id) + WHERE (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') AND + $conditionsToString + "; + $result = Database::query($sql); + $row = Database::fetch_array($result, 'ASSOC'); + return ($row['sum_score'] / $row['sum_max_score'])*100; + + } + /** * This function gets time spent in learning path for a student inside a course * @param int|array Student id(s) @@ -1478,12 +1575,12 @@ class Tracking $a_course = CourseManager::get_course_information($course_code); if (!empty($a_course)) { // table definition - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); - $tbl_document = Database :: get_course_table(TABLE_DOCUMENT); + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $tbl_document = Database :: get_course_table(TABLE_DOCUMENT); $course_id = $a_course['real_id']; if (is_array($student_id)) { - $student_id = array_map('intval', $student_id); - $condition_user = " AND ip.insert_user_id IN (".implode(',', $student_id).") "; + $studentList = array_map('intval', $student_id); + $condition_user = " AND ip.insert_user_id IN ('".implode(',', $studentList)."') "; } else { $student_id = intval($student_id); $condition_user = " AND ip.insert_user_id = '$student_id' "; @@ -1495,7 +1592,7 @@ class Tracking $condition_session = " AND pub.session_id = $session_id "; } - $sql = "SELECT count(ip.tool) + $sql = "SELECT count(ip.tool) AS count FROM $tbl_item_property ip INNER JOIN $tbl_document pub ON ip.ref = pub.id WHERE ip.c_id = $course_id AND @@ -1505,7 +1602,7 @@ class Tracking $condition_user $condition_session "; $rs = Database::query($sql); $row = Database::fetch_row($rs); - return $row[0]; + return $row['count']; } return null; } @@ -1517,83 +1614,98 @@ class Tracking * @param int Session id (optional), if param $session_id is null(default) return count of assignments including sessions, 0 = session is not filtered * @return int Count of assignments */ - public static function count_student_assignments($student_id, $course_code, $session_id = null) + public static function count_student_assignments($student_id, $course_code = null, $session_id = null) { + if (empty($student_id)) { + return 0; + } + + $conditions = array(); + // Get the information of the course $a_course = CourseManager::get_course_information($course_code); if (!empty($a_course)) { - // table definition - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); - $tbl_student_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); $course_id = $a_course['real_id']; + $conditions[]= " ip.c_id = $course_id AND pub.c_id = $course_id "; + } - if (is_array($student_id)) { - $condition_user = " AND ip.insert_user_id IN (".implode(',',$student_id).") "; - } else { - $condition_user = " AND ip.insert_user_id = '$student_id' "; - } - - $condition_session = ""; - if (isset($session_id)) { - $session_id = intval($session_id); - $condition_session = " AND pub.session_id = $session_id "; - } + // table definition + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $tbl_student_publication = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "SELECT count(ip.tool) - FROM $tbl_item_property ip INNER JOIN $tbl_student_publication pub - ON ip.ref = pub.id - WHERE ip.c_id = $course_id AND - pub.c_id = $course_id AND - ip.tool='work' - $condition_user $condition_session "; - $rs = Database::query($sql); - $row = Database::fetch_row($rs); - return $row[0]; + if (is_array($student_id)) { + $studentList = array_map('intval', $student_id); + $conditions[]= " ip.insert_user_id IN ('".implode("','", $studentList)."') "; + } else { + $student_id = intval($student_id); + $conditions[]= " ip.insert_user_id = '$student_id' "; } - return null; + if (isset($session_id)) { + $session_id = intval($session_id); + $conditions[]= " pub.session_id = $session_id "; + } + $conditionToString = implode('AND', $conditions); + + $sql = "SELECT count(ip.tool) as count + FROM $tbl_item_property ip + INNER JOIN $tbl_student_publication pub ON ip.ref = pub.id + WHERE + ip.tool='work' AND + $conditionToString"; + $rs = Database::query($sql); + $row = Database::fetch_array($rs, 'ASSOC'); + return $row['count']; } /** * Count messages per student inside forum tool - * @param int Student id + * @param int|array Student id * @param string Course code - * @param int Session id (optional), if param $session_id is null(default) return count of messages including sessions, 0 = session is not filtered + * @param int Session id (optional), if param $session_id is + * null(default) return count of messages including sessions, 0 = session is not filtered * @return int Count of messages */ - public static function count_student_messages($student_id, $courseCode, $session_id = null) + public static function count_student_messages($student_id, $courseCode = null, $session_id = null) { - $student_id = intval($student_id); + if (empty($student_id)) { + return 0; + } $courseInfo = api_get_course_info($courseCode); + $courseCondition = null; + $conditions = array(); if (!empty($courseInfo)) { - - // Table definition - $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST); - $tbl_forum = Database :: get_course_table(TABLE_FORUM); $course_id = $courseInfo['real_id']; + $conditions[]= " post.c_id = $course_id AND forum.c_id = $course_id "; + } - if (is_array($student_id)) { - $condition_user = " AND post.poster_id IN (".implode(',',$student_id).") "; - } else { - $condition_user = " AND post.poster_id = '$student_id' "; - } - - $condition_session = ""; - if (isset($session_id)) { - $session_id = intval($session_id); - $condition_session = " AND forum.session_id = $session_id"; - } + // Table definition. + $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST); + $tbl_forum = Database :: get_course_table(TABLE_FORUM); - $sql = "SELECT 1 FROM $tbl_forum_post post INNER JOIN $tbl_forum forum - ON forum.forum_id = post.forum_id - WHERE post.c_id = $course_id AND - forum.c_id = $course_id - $condition_user $condition_session "; - $rs = Database::query($sql); - return Database::num_rows($rs); + if (is_array($student_id)) { + $studentList = array_map('intval', $student_id); + $conditions[]= " post.poster_id IN ('".implode("','", $studentList)."') "; } else { - return null; + $student_id = intval($student_id); + $conditions[]= " post.poster_id = '$student_id' "; + } + + if (isset($session_id)) { + $session_id = intval($session_id); + $conditions[]= " forum.session_id = $session_id"; } + + $conditionsToString = implode('AND ', $conditions); + $sql = "SELECT count(poster_id) as count + FROM $tbl_forum_post post INNER JOIN $tbl_forum forum + ON forum.forum_id = post.forum_id + WHERE $conditionsToString"; + + $rs = Database::query($sql); + $row = Database::fetch_array($rs, 'ASSOC'); + $count = $row['count']; + return $count; } /** diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 268bba7525..da644070dd 100644 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -205,892 +205,192 @@ if (empty($session_id) || in_array($display, array('accessoverview','lpprogresso echo ''; -if (empty($session_id)) { - // Getting courses followed by a coach (No session courses). - $courses = CourseManager::get_course_list_as_coach($user_id, false); +// Getting courses followed by a coach (No session courses). +$courses = CourseManager::get_course_list_as_coach($user_id, false); - // Courses with no session: - if (isset($courses[0])) { - $courses = $courses[0]; - } - - // Getting students from courses and courses in sessions (To show the total students that the user follows) - $students = CourseManager::get_user_list_from_courses_as_coach($user_id); - - // If is drh - if ($is_drh) { - if (api_drh_can_access_all_session_content()) { - $studentList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id()); - - $students = array(); - foreach ($studentList as $studentData) { - $students[] = $studentData['user_id']; - } - $courses_of_the_platform = SessionManager::getAllCoursesFromAllSessionFromDrh(api_get_user_id()); +// Courses with no session: +if (isset($courses[0])) { + $courses = $courses[0]; +} - foreach ($courses_of_the_platform as $course) { - $courses[$course] = $course; - } - $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id()); +// If is drh +if ($is_drh) { + if (api_drh_can_access_all_session_content()) { + $studentList = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id()); - } else { - $students = array_keys(UserManager::get_users_followed_by_drh($user_id, STUDENT)); - $courses_of_the_platform = CourseManager::get_courses_followed_by_drh($user_id); - foreach ($courses_of_the_platform as $course) { - $courses[$course['code']] = $course['code']; - } - $sessions = SessionManager::get_sessions_followed_by_drh($user_id); + $students = array(); + foreach ($studentList as $studentData) { + $students[] = $studentData['user_id']; } - } else { - // Sessions for the coach - $sessions = Tracking::get_sessions_coached_by_user($user_id); - } - - // Courses for the user - $count_courses = count($courses); - - // Sessions for the user - $count_sessions = count($sessions); - - // Students - $nb_students = count($students); - - $total_time_spent = 0; - $total_courses = 0; - $avg_total_progress = 0; - $avg_results_to_exercises = 0; - $nb_inactive_students = 0; - $nb_posts = $nb_assignments = 0; - - if (!empty($students)) { - foreach ($students as $student_id) { - // inactive students - $last_connection_date = Tracking::get_last_connection_date($student_id, true, true); - - if ($last_connection_date !== false) { - if (time() - (3600 * 24 * 7) > $last_connection_date) { - $nb_inactive_students++; - } - } else { - $nb_inactive_students++; - } + $courses_of_the_platform = SessionManager::getAllCoursesFromAllSessionFromDrh(api_get_user_id()); - $total_time_spent += Tracking::get_time_spent_on_the_platform($student_id); - $total_courses += Tracking::count_course_per_student($student_id); - $avg_student_progress = 0; - $avg_student_score = 0; - $nb_courses_student = 0; - - foreach ($courses as $course_code) { - if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) { - $nb_courses_student++; - $nb_posts += Tracking :: count_student_messages($student_id, $course_code); - $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code); - $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code); - $myavg_temp = Tracking :: get_avg_student_score($student_id, $course_code); - - if (is_numeric($myavg_temp)) { - $avg_student_score += $myavg_temp; - } - - if ($nb_posts !== null && $nb_assignments !== null && $avg_student_progress !== null && $avg_student_score !== null) { - //if one of these scores is null, it means that we had a problem connecting to the right database, so don't count it in - $nb_courses_student++; - } - } - } - - // average progress of the student - $avg_student_progress = $nb_courses_student ?$avg_student_progress / $nb_courses_student:0; - $avg_total_progress += $avg_student_progress; - - // average test results of the student - $avg_student_score = $avg_student_score?$avg_student_score / $nb_courses_student:0; - $avg_results_to_exercises += $avg_student_score; + foreach ($courses_of_the_platform as $course) { + $courses[$course] = $course; } - } - - if ($nb_students > 0 && $view != 'admin') { - - // average progress - $avg_total_progress = $avg_total_progress / $nb_students; - // average results to the tests - $avg_results_to_exercises = $avg_results_to_exercises / $nb_students; - // average courses by student - $avg_courses_per_student = round($count_courses / $nb_students, 2); - // average time spent on the platform - $avg_time_spent = $total_time_spent / $nb_students; - // average assignments - $nb_assignments = $nb_assignments / $nb_students; - // average posts - $nb_posts = $nb_posts / $nb_students; - - echo Display::page_subheader(get_lang('Overview')); + $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id()); - echo '
- - - - - - - - - - - - - -
'.get_lang('FollowedUsers').''.$nb_students.'
'.get_lang('FollowedCourses').''.$count_courses.'
'.get_lang('FollowedSessions').''.$count_sessions.'
'; - echo '
'; - - echo Display::page_subheader(get_lang('Students').' ('.$nb_students.')'); - - if ($export_csv) { - //csv part - $csv_content[] = array(get_lang('Students', '')); - $csv_content[] = array(get_lang('InactivesStudents', ''), $nb_inactive_students ); - $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform', ''), $avg_time_spent); - $csv_content[] = array(get_lang('AverageCoursePerStudent', ''), $avg_courses_per_student); - $csv_content[] = array(get_lang('AverageProgressInLearnpath', ''), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%'); - $csv_content[] = array(get_lang('AverageResultsToTheExercices', ''), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%'); - $csv_content[] = array(get_lang('AveragePostsInForum', ''), $nb_posts); - $csv_content[] = array(get_lang('AverageAssignments', ''), $nb_assignments); - $csv_content[] = array(); - } else { - - $lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago')); - - $countActiveUsers = SessionManager::getCountUserTracking(null, 1); - $countInactiveUsers = SessionManager::getCountUserTracking(null, 0); - $countSleepingTeachers = SessionManager::getTeacherTracking(api_get_user_id(), 1, $lastConnectionDate, true); - $countSleepingStudents =SessionManager::getCountUserTracking(null, 1, $lastConnectionDate); - - $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php'); - $form->addElement('text', 'keyword', get_lang('User')); - $form->addElement('button', 'submit', get_lang('Search')); - $form->display(); - - // html part - echo '
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'.Display::url(get_lang('ActiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=1').''.$countActiveUsers.'
'.Display::url(get_lang('InactiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=0').''.$countInactiveUsers.'
'.Display::url(get_lang('SleepingTeachers'), api_get_path(WEB_CODE_PATH).'mySpace/teachers.php?sleeping_days=15').''.$countSleepingTeachers.'
'.Display::url(get_lang('SleepingStudents'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?sleeping_days=15').''.$countSleepingStudents.'
'.get_lang('AverageCoursePerStudent').''.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'
'.get_lang('InactivesStudents').''.$nb_inactive_students.'
'.get_lang('AverageTimeSpentOnThePlatform').''.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'
'.get_lang('AverageProgressInLearnpath').''.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'
'.get_lang('AvgCourseScore').''.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'
'.get_lang('AveragePostsInForum').''.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'
'.get_lang('AverageAssignments').''.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'
- - '.get_lang('SeeStudentList').' - -

'; - } } else { - $avg_total_progress = null; - $avg_results_to_exercises = null; - $avg_courses_per_student = null; - $avg_time_spent = null; - $nb_assignments = null; - $nb_posts = null; - } -} else { - // If is drh - if ($is_drh) { + $students = array_keys(UserManager::get_users_followed_by_drh($user_id, STUDENT)); $courses_of_the_platform = CourseManager::get_courses_followed_by_drh($user_id); - $courses_from_session = SessionManager::get_course_list_by_session_id($session_id); - - $courses = array(); - foreach ($courses_from_session as $course_item) { - if (api_drh_can_access_all_session_content()) { - $courses[$course_item['code']] = $course_item['code']; - } else { - if (isset($courses_of_the_platform[$course_item['code']])) { - $courses[$course_item['code']] = $course_item['code']; - } - } - } - - if (empty($courses)) { - Display::display_warning_message(get_lang('NoResults')); + foreach ($courses_of_the_platform as $course) { + $courses[$course['code']] = $course['code']; } - } else { - $courses = Tracking::get_courses_followed_by_coach($user_id, $session_id); + $sessions = SessionManager::get_sessions_followed_by_drh($user_id); } +} else { + // Getting students from courses and courses in sessions (To show the total students that the user follows) + $students = CourseManager::get_user_list_from_courses_as_coach($user_id); - // Courses for the user - $count_courses = count($courses); - - // Sessions for the user - $count_sessions = count($sessions); -} -/* -if ($count_courses || $count_sessions) { - //If we are in course - if (empty($session_id)) { - if ($count_courses) { - $title = Display::return_icon('course.gif').' '.get_lang('Courses').' ('.$count_courses.') '; - } - } else { - //If we are in Course Session - $session_name = api_get_session_name($session_id); - $title = Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.$session_name; - $menu_items[] = ''.get_lang('TeacherInterface').''; - } + // Sessions for the coach + $sessions = Tracking::get_sessions_coached_by_user($user_id); } -if ((api_is_allowed_to_create_course() || api_is_drh()) && in_array($view, array('teacher', 'drh'))) { - - // Courses - if ($count_courses) { - - echo Display::page_subheader($title); - - $table = new SortableTable('courses_my_space', 'get_number_of_courses', array('MySpace','get_course_data')); - $parameters['view'] = 'teacher'; - $parameters['class'] = 'data_table'; - $table->set_additional_parameters($parameters); - $table->set_header(0, get_lang('CourseTitle'), false); - $table->set_header(1, get_lang('NbStudents'), false); - $table->set_header(2, get_lang('AvgTimeSpentInTheCourse').' '.Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false); - $table->set_header(3, get_lang('AvgStudentsProgress').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); - $table->set_header(4, get_lang('AvgCourseScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); - $table->set_header(5, get_lang('AvgExercisesScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); - $table->set_header(6, get_lang('AvgMessages'), false); - $table->set_header(7, get_lang('AverageAssignments'), false); - $table->set_header(8, get_lang('Details'), false); - - $csv_content[] = array ( - get_lang('CourseTitle', ''), - get_lang('NbStudents', ''), - get_lang('AvgTimeSpentInTheCourse', ''), - get_lang('AvgStudentsProgress', ''), - get_lang('AvgCourseScore', ''), - get_lang('AvgExercisesScore', ''), - get_lang('AvgMessages', ''), - get_lang('AverageAssignments', '') - ); - $table->display(); - } - - // Display list of sessions - - if ($count_sessions > 0 && !isset($_GET['session_id'])) { - echo Display::page_subheader(Display::return_icon('session.png').' '.get_lang('Sessions').' ('.$count_sessions.')'); - - $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions_tracking'; - - //The order is important you need to check the the $column variable in the model.ajax.php file - $columns = array( - get_lang('Title'), - get_lang('Date'), - get_lang('NbCoursesPerSession'), - get_lang('NbStudentPerSession'), - get_lang('Details') - ); - - // Column config - $columnModel = array( - array('name'=>'name', 'index'=>'name', 'width'=>'255', 'align'=>'left'), - array('name'=>'date', 'index'=>'date', 'width'=>'150', 'align'=>'left','sortable'=>'false'), - array('name'=>'course_per_session', 'index'=>'course_per_session', 'width'=>'150','sortable'=>'false'), - array('name'=>'student_per_session', 'index'=>'student_per_session', 'width'=>'100','sortable'=>'false'), - array('name'=>'details', 'index'=>'details', 'width'=>'100','sortable'=>'false'), - ); - - $extraParams = array( - 'autowidth' => 'true', - 'height' => 'auto' - ); - - $js = ''; - - $nb_sessions_past = $nb_sessions_current = 0; - $courses = array(); - - foreach ($sessions as $session) { - $visibility = api_get_session_visibility($session['id']); - if ($visibility == SESSION_AVAILABLE) { - $nb_sessions_current ++; - } else { - $nb_sessions_past++; - } - $courses = array_merge($courses, Tracking::get_courses_list_from_session($session['id'])); - } - - $nb_courses_per_session = null; - $nb_students_per_session = null; - - if ($count_sessions > 0) { - $nb_courses_per_session = round(count($courses) / $count_sessions, 2); - $nb_students_per_session = round($nb_students / $count_sessions, 2); - } - - if ($export_csv) { - //csv part - $csv_content[] = array(get_lang('Sessions', '')); - $csv_content[] = array(get_lang('NbActiveSessions', '').';'.$nb_sessions_current); - $csv_content[] = array(get_lang('NbInactiveSessions', '').';'.$nb_sessions_past); - $csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session); - $csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session); - $csv_content[] = array(); - } else { - echo ' -
+// Courses for the user +$count_courses = count($courses); + +// Sessions for the user +$count_sessions = count($sessions); + +// Students +$nb_students = count($students); + +$total_time_spent = 0; +$total_courses = 0; +$avg_total_progress = 0; +$avg_results_to_exercises = 0; +$nb_inactive_students = 0; +$nb_posts = $nb_assignments = 0; + +$inactiveTime = time() - (3600 * 24 * 7); + +$daysAgo = 7; +if (!empty($students)) { + + $studentIds = array_values($students); + $nb_students = count($studentIds); + + // Inactive students + $inactiveUsers = Tracking::getInactiveUsers($studentIds, $daysAgo); + $totalTimeSpent = Tracking::get_time_spent_on_the_platform($studentIds); + + $posts = Tracking::count_student_messages($studentIds); + $countAssignments = Tracking::count_student_assignments($studentIds); + $progress = Tracking::get_avg_student_progress($studentIds); + $averageScore = Tracking::getAverageStudentScore($studentIds); + + // average progress + $avg_total_progress = $progress / $nb_students; + // average results to the tests + $avg_results_to_exercises = $averageScore; + // average assignments + $nb_assignments = $countAssignments / $nb_students; + // average posts + $nb_posts = $posts ; + + $avg_time_spent = $totalTimeSpent; + + $avg_courses_per_student = $count_courses / $nb_students; + + echo Display::page_subheader(get_lang('Overview')); + + echo '
+ + + + + + + + + + + + + +
'.get_lang('FollowedUsers').''.$nb_students.'
'.get_lang('FollowedCourses').''.$count_courses.'
'.get_lang('FollowedSessions').''.$count_sessions.'
'; + echo '
'; + + echo Display::page_subheader(get_lang('Students').' ('.$nb_students.')'); + + if ($export_csv) { + //csv part + $csv_content[] = array(get_lang('Students', '')); + $csv_content[] = array(get_lang('InactivesStudents', ''), $nb_inactive_students); + $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform', ''), $avg_time_spent); + $csv_content[] = array(get_lang('AverageCoursePerStudent', ''), $avg_courses_per_student); + $csv_content[] = array(get_lang('AverageProgressInLearnpath', ''), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%'); + $csv_content[] = array(get_lang('AverageResultsToTheExercices', ''), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%'); + $csv_content[] = array(get_lang('AveragePostsInForum', ''), $nb_posts); + $csv_content[] = array(get_lang('AverageAssignments', ''), $nb_assignments); + $csv_content[] = array(); + } else { + $lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago')); + $countActiveUsers = SessionManager::getCountUserTracking(null, 1); + $countInactiveUsers = SessionManager::getCountUserTracking(null, 0); + $countSleepingTeachers = SessionManager::getTeacherTracking(api_get_user_id(), 1, $lastConnectionDate, true); + $countSleepingStudents = SessionManager::getCountUserTracking(null, 1, $lastConnectionDate); + + $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php'); + $form->addElement('text', 'keyword', get_lang('User')); + $form->addElement('button', 'submit', get_lang('Search')); + $form->display(); + + // html part + echo '
- - + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'.get_lang('NbActiveSessions').''.$nb_sessions_current.''.Display::url(get_lang('ActiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=1').''.$countActiveUsers.'
'.Display::url(get_lang('InactiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=0').''.$countInactiveUsers.'
'.get_lang('NbInactiveSessions').''.$nb_sessions_past.''.Display::url(get_lang('SleepingTeachers'), api_get_path(WEB_CODE_PATH).'mySpace/teachers.php?sleeping_days=15').''.$countSleepingTeachers.'
'.Display::url(get_lang('SleepingStudents'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?sleeping_days=15').''.$countSleepingStudents.'
'.get_lang('AverageCoursePerStudent').''.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'
'.get_lang('InactivesStudents').''.$nb_inactive_students.'
'.get_lang('AverageTimeSpentOnThePlatform').''.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'
'.get_lang('AverageProgressInLearnpath').''.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'
'.get_lang('AvgCourseScore').''.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'
'.get_lang('AveragePostsInForum').''.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'
'.get_lang('AverageAssignments').''.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'
-
'; - } - echo $js; - echo Display::grid_html('session_tracking'); + + '.get_lang('SeeStudentList').' + +

'; } } -if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourstudents') { - - echo ''.get_lang('DisplayCoaches').' | '; - echo ''.get_lang('DisplayUserOverview').''; - if ($display == 'useroverview') { - echo ' ( '.get_lang('ExportUserOverviewOptions').' )'; - } - echo ' | '.get_lang('DisplaySessionOverview').''; - echo ' | '.get_lang('DisplayAccessOverview').''; - echo ' | '.get_lang('DisplaySurveyOverview').''; - echo ' | '.get_lang('DisplayLpProgressOverview').''; - echo ' | '.get_lang('DisplayProgressOverview').''; - echo ' | '.get_lang('DisplayExerciseProgress').''; - echo ' | '.get_lang('DisplayCourseOverview').''; - echo ' | '.get_lang('LPQuestionListResults').''; - echo ' | '.get_lang('LPExerciseResultsBySession').''; - echo '

'; - - if ($is_platform_admin && $view == 'admin' && in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))) { - //Session Filter - $sessionFilter = new FormValidator('session_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session'; - $sessionList = array(); - $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null; - if (!empty($sessionId)) { - $sessionList = array(); - $sessionInfo = SessionManager::fetch($sessionId); - $sessionList[] = array('id' => $sessionInfo['id'], 'text' => $sessionInfo['name']); - } - $sessionFilter->addElement('select_ajax', 'session_name', get_lang('SearchSession'), null, array('url' => $url, 'defaults' => $sessionList)); - $courseListUrl = api_get_self(); - - echo '
'; - echo $sessionFilter->return_form(); - echo '
'; - echo ''; - // Course filter. - if (in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))) { - $courseFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $a = 'search_course_by_session'; - if ( $display == 'exerciseprogress') { - $a = 'search_course'; - } - $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a='. $a .'&session_id=' . $_GET['session_id']; - $courseList = array(); - $courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null; - if (!empty($courseId)) { - $courseList = array(); - $courseInfo = api_get_course_info_by_id($courseId); - $courseList[] = array('id' => $courseInfo['real_id'], 'text' => $courseInfo['name']); - } - $courseFilter->addElement('select_ajax', 'course_name', get_lang('SearchCourse'), null, array('url' => $url, 'defaults' => $courseList)); - $courseListUrl = api_get_self(); - - echo '
'; - echo $courseFilter->return_form(); - echo '
'; - echo ''; - } - //Student Filter - if (in_array($display, array('accessoverview'))) { - $courseListUrl = api_get_self(); - $studentFilter = new FormValidator('student_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_user_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id']; - $studentList = array(); - $studentId = isset($_GET['student_id']) ? $_GET['student_id'] : null; - if (!empty($studentId)) { - $studentList = array(); - $studentInfo = UserManager::get_user_info_by_id($studentId); - $studentList[] = array('id' => $studentInfo['id'], 'text' => $studentInfo['username']); - } - - $studentFilter->addElement('text', 'from', get_lang('From'), array('id' => 'date_from'), array('defaults' => $_GET['date_from'])); - $studentFilter->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to'), $_GET['date_to']); - - $studentFilter->addElement('select_ajax', 'student_name', get_lang('SearchStudent'), null, array('url' => $url, 'defaults' => $studentList), array('class' => 'pull-left')); - $options = array( - '' => get_lang('Select'), - STUDENT => get_lang('Student'), - COURSEMANAGER => get_lang('CourseManager'), - DRH => get_lang('Drh'), - ); - $studentFilter->addElement('select', 'profile', get_lang('Profile'),$options, array('id' => 'profile')); - - echo '
'; - echo $studentFilter->return_form(); - echo '
'; - - //TODO fix this hack - $date_to = (!empty($_GET['date_to'])) ? ' $(\'#date_to\').val(\'' . $_GET['date_to'] . '\'); ' : ''; - $date_from = (!empty($_GET['date_from'])) ? ' $(\'#date_from\').val(\'' . $_GET['date_from'] . '\'); ' : ''; - echo ''; - } - - if (in_array($display, array('surveyoverview'))) { - $surveyOverview = new FormValidator('survey_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_survey_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id'] . '&survey_id=' . $_GET['survey_id']; - $surveyList = array(); - $surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; - $courseId = isset($_GET['course_id']) ? intval($_GET['course_id']) : null; - if (!empty($surveyId)) { - $course = api_get_course_info_by_id($courseId); - $surveyList = array(); - $exerciseInfo = survey_manager::get_survey($surveyId, 0, $course['code']); - $surveyList[] = array('id' => $exerciseInfo['id'], 'text' => $exerciseInfo['title']); - } - $surveyOverview->addElement('select_ajax', 'survey_name', get_lang('SearchSurvey'), null, array('url' => $url, 'defaults' => $surveyList)); - $courseListUrl = api_get_self(); - - echo '
'; - echo $surveyOverview ->return_form(); - echo '
'; - - echo ''; - } - - if (in_array($display, array('exerciseprogress'))) { - //exercise - $exerciseFilter = new FormValidator('student_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_exercise_by_course&session_id=' . $_GET['session_id'] . '&course_id=' . $_GET['course_id']; - $exerciseList = array(); - $exerciseId = isset($_GET['exercise_id']) ? $_GET['exercise_id'] : null; - if (!empty($exerciseId)) { - $exerciseList = array(); - $exerciseInfo = current(get_exercise_by_id($exerciseId)); - $exerciseList[] = array('id' => $exerciseInfo['id'], 'text' => $exerciseInfo['title']); - } - $exerciseFilter->addElement('select_ajax', 'exercise_name', get_lang('SearchExercise'), null, array('url' => $url, 'defaults' => $exerciseList)); - $courseListUrl = api_get_self(); - - echo '
'; - echo $exerciseFilter->return_form(); - echo '
'; - - echo ''; - - //answer Type - $answerFilter = new FormValidator('answer_filter', 'get', '', '', array('class'=> 'form-horizontal'), false); - $options = array( - 2 => get_lang('all'), - 0 => get_lang('incorrect'), - 1 => get_lang('correct'), - ); - $answerFilter->addElement('select', 'answer', get_lang('AnswerIndicator'),$options, array('id' => 'answer')); - $courseListUrl = api_get_self(); - - echo '
'; - echo $answerFilter->return_form(); - echo '
'; - - echo ''; - - } - } - - if ($display === 'useroverview') { - MySpace::display_tracking_user_overview(); - } else if($display == 'sessionoverview') { - MySpace::display_tracking_session_overview(); - } else if($display == 'accessoverview') { - if (!empty($_GET['session_id'])) { - if (!empty($_GET['course_id'])) { - if(!empty($_GET['date_to']) && (!empty($_GET['date_from']))) { - if (!empty($_GET['student_id'])) { - echo MySpace::display_tracking_access_overview(intval($_GET['session_id']), intval($_GET['course_id']), intval($_GET['student_id']), '', $_GET['date_to'], $_GET['date_from']); - } else if (!empty($_GET['profile'])) { - echo MySpace::display_tracking_access_overview(intval($_GET['session_id']), intval($_GET['course_id']), '', $_GET['profile'], $_GET['date_to'], $_GET['date_from']); - } else { - Display::display_warning_message(get_lang('ChooseStudentOrProfile')); - } - } else { - Display::display_warning_message(get_lang('ChooseStartDateAndEndDate')); - } - } else { - Display::display_warning_message(get_lang('ChooseCourse')); - } - } else { - Display::display_warning_message(get_lang('ChooseSession')); - } - } else if($display == 'lpprogressoverview') { - if (!empty($_GET['session_id'])) { - if (!empty($_GET['course_id'])) - { - echo MySpace::display_tracking_lp_progress_overview(intval($_GET['session_id']), intval($_GET['course_id'])); - } else - { - Display::display_warning_message(get_lang('ChooseCourse')); - } - } else { - Display::display_warning_message(get_lang('ChooseSession')); - } - } else if($display == 'progressoverview') { - if (!empty($_GET['session_id'])) { - if (!empty($_GET['course_id'])) { - echo MySpace::display_tracking_progress_overview(intval($_GET['session_id']), intval($_GET['course_id'])); - } else { - Display::display_warning_message(get_lang('ChooseCourse')); - } - } else { - Display::display_warning_message(get_lang('ChooseSession')); - } - } else if($display == 'exerciseprogress') { - if (!empty($_GET['course_id'])) { - if (!empty($_GET['exercise_id'])) { - $answer = (isset($_GET['answer'])) ? intval($_GET['answer']) : 2; - echo MySpace::display_tracking_exercise_progress_overview(intval($_GET['session_id']), intval($_GET['course_id']), intval($_GET['exercise_id']), $answer); - } else { - Display::display_warning_message(get_lang('ChooseExercise')); - } - } else { - Display::display_warning_message(get_lang('ChooseCourse')); - } - } else if($display == 'surveyoverview') { - if (!empty($_GET['session_id'])) { - if (!empty($_GET['course_id'])) { - if (!empty($_GET['survey_id'])) { - echo MySpace::display_survey_overview(intval($_GET['session_id']), intval($_GET['course_id']), intval($_GET['survey_id'])); - } else { - Display::display_warning_message(get_lang('ChooseSurvey')); - } - } else { - Display::display_warning_message(get_lang('ChooseCourse')); - } - } else { - Display::display_warning_message(get_lang('ChooseSession')); - } - } else if($display == 'courseoverview') { - MySpace::display_tracking_course_overview(); - } else { - if ($export_csv) { - $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); - } else { - $is_western_name_order = api_is_western_name_order(); - } - $sort_by_first_name = api_sort_by_first_name(); - $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0; - $tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1'))) ? $_GET['tracking_list_coaches_direction'] : 'DESC'; - // Prepare array for column order - when impossible, use some of user names. - if ($is_western_name_order) { - $order = array(0 => 'firstname', 1 => 'lastname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname')); - } else { - $order = array(0 => 'lastname', 1 => 'firstname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname')); - } - $table = new SortableTable('tracking_list_coaches_myspace', 'count_coaches', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0); - $parameters['view'] = 'admin'; - $table->set_additional_parameters($parameters); - if ($is_western_name_order) { - $table->set_header(0, get_lang('FirstName'), true); - $table->set_header(1, get_lang('LastName'), true); - } else { - $table->set_header(0, get_lang('LastName'), true); - $table->set_header(1, get_lang('FirstName'), true); - } - $table->set_header(2, get_lang('TimeSpentOnThePlatform'), false); - $table->set_header(3, get_lang('LastConnexion'), false); - $table->set_header(4, get_lang('NbStudents'), false); - $table->set_header(5, get_lang('CountCours'), false); - $table->set_header(6, get_lang('NumberOfSessions'), false); - $table->set_header(7, get_lang('Sessions'), false); - - if ($is_western_name_order) { - $csv_header[] = array ( - get_lang('FirstName', ''), - get_lang('LastName', ''), - get_lang('TimeSpentOnThePlatform', ''), - get_lang('LastConnexion', ''), - get_lang('NbStudents', ''), - get_lang('CountCours', ''), - get_lang('NumberOfSessions', '') - ); - } else { - $csv_header[] = array ( - get_lang('LastName', ''), - get_lang('FirstName', ''), - get_lang('TimeSpentOnThePlatform', ''), - get_lang('LastConnexion', ''), - get_lang('NbStudents', ''), - get_lang('CountCours', ''), - get_lang('NumberOfSessions', '') - ); - } - - $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - - $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date - FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login - WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id - GROUP BY user_id "; - - if ($_configuration['multiple_access_urls']) { - $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { - $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date - FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login , $tbl_session_rel_access_url session_rel_url - WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id AND access_url_id = $access_url_id AND session_rel_url.session_id=id_session - GROUP BY user_id "; - } - } - if (!empty($order[$tracking_column])) { - $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction; - } - - $result_coaches = Database::query($sqlCoachs); - $total_no_coaches = Database::num_rows($result_coaches); - $global_coaches = array(); - while ($coach = Database::fetch_array($result_coaches)) { - $global_coaches[$coach['user_id']] = $coach; - } - - $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date - FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' - WHERE id_coach=user_id AND login_user_id=user_id - GROUP BY user_id - ORDER BY login_date '.$tracking_direction; - - if ($_configuration['multiple_access_urls']) { - $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { - $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date - FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url - WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = '.$access_url_id.' AND session_rel_url.session_id=session.id - GROUP BY user_id - ORDER BY login_date '.$tracking_direction; - } - } - - $result_sessions_coach = Database::query($sql_session_coach); - $total_no_coaches += Database::num_rows($result_sessions_coach); - while ($coach = Database::fetch_array($result_sessions_coach)) { - $global_coaches[$coach['user_id']] = $coach; - } - - $all_datas = array(); - - foreach ($global_coaches as $id_coach => $coaches) { - - $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id'])); - $last_connection = Tracking :: get_last_connection_date($coaches['user_id']); - $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id'])); - $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id'])); - $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id'])); - - $table_row = array(); - if ($is_western_name_order) { - $table_row[] = $coaches['firstname']; - $table_row[] = $coaches['lastname']; - } else { - $table_row[] = $coaches['lastname']; - $table_row[] = $coaches['firstname']; - } - $table_row[] = $time_on_platform; - $table_row[] = $last_connection; - $table_row[] = $nb_students; - $table_row[] = $nb_courses; - $table_row[] = $nb_sessions; - $table_row[] = ''; - $all_datas[] = $table_row; - - if ($is_western_name_order) { - $csv_content[] = array( - api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset), - api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset), - $time_on_platform, - $last_connection, - $nb_students, - $nb_courses, - $nb_sessions - ); - } else { - $csv_content[] = array( - api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset), - api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset), - $time_on_platform, - $last_connection, - $nb_students, - $nb_courses, - $nb_sessions - ); - } - } - - if ($tracking_column != 3) { - if ($tracking_direction == 'DESC') { - usort($all_datas, 'rsort_users'); - } else { - usort($all_datas, 'sort_users'); - } - } - - if ($export_csv && $tracking_column != 3) { - usort($csv_content, 'sort_users'); - } - if ($export_csv) { - $csv_content = array_merge($csv_header, $csv_content); - } - - foreach ($all_datas as $row) { - $table->addRow($row, 'align="right"'); - } - $table->display(); - } -}*/ - // Send the csv file if asked if ($export_csv) { ob_end_clean(); @@ -1098,16 +398,6 @@ if ($export_csv) { exit; } -//footer if (!$export_csv) { Display::display_footer(); } - -/** - * Get number of courses for sortable with pagination - * @return int - */ -function get_number_of_courses() { - global $courses; - return count($courses); -}