From 275962c0087facccb32eca38b75cfcc85b7aadef Mon Sep 17 00:00:00 2001 From: Eric Marguin Date: Mon, 26 Mar 2007 11:35:26 +0200 Subject: [PATCH] [svn r11689] add a function in course.lib.php to select all students of the course, even students subscribed throug h a session --- main/inc/lib/course.lib.php | 38 +++++++++++++++++++++++++++++++++++++ main/tracking/courseLog.php | 7 +------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 20008a4dc6..54ab3201cb 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1037,6 +1037,44 @@ class CourseManager return $result_array; } + + + /** + * Return user info array of all users registered in the specified real or virtual course + * This only returns the users that are registered in this actual course, not linked courses. + * + * @param string $course_code + * @param boolean $full list to true if we want sessions students too + * @return array with user id + */ + function get_student_list_from_course_code($course_code, $full_list=false) + { + $a_students = array(); + + // students directly subscribed to the course + $table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $sql_query = "SELECT user_id FROM $table WHERE `course_code` = '$course_code' AND `status` = 5"; + $rs = api_sql_query($sql_query, __FILE__, __LINE__); + while($student = mysql_fetch_array($rs)) + { + $a_students[$student['user_id']] = $student['user_id']; + } + + // students subscribed to the course through a session + + if(api_get_setting('use_session_mode')=='true' && $full_list) + { + $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $sql_query = "SELECT DISTINCT id_user as user_id FROM $table WHERE `course_code` = '$course_code'"; + $rs = api_sql_query($sql_query, __FILE__, __LINE__); + while($student = mysql_fetch_array($rs)) + { + $a_students[$student['user_id']] = $student['user_id']; + } + } + + return $a_students; + } /** * Return user info array of all users registered in the specified course diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index 3b47d59b3d..a9dd4fbb87 100644 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -116,12 +116,7 @@ $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin; -$a_students_temp = CourseManager :: get_user_list_from_course_code($_course['id']); -foreach($a_students_temp as $student) -{ - if($student['status'] == 5) - $a_students[] = $student['user_id']; -} +$a_students = CourseManager :: get_student_list_from_course_code($_course['id'], true); $nbStudents = count($a_students); /**