$count_quiz = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_quiz WHERE active <> -1",__FILE__,__LINE__));
$quiz_avg_total_score = 0;
if (!empty($count_quiz[0]) && !empty($student_id)) {
$condition_user = "";
if (is_array($student_id)) {
$condition_user = " AND exe_user_id IN (".implode(',',$student_id).") ";
} else {
$condition_user = " AND exe_user_id = '$student_id' ";
}
return $quiz_avg_total_score/$count_exe;
}
}
else
{
return null;
}
$sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score
FROM $tbl_stats_exercise
WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1)
$condition_user
AND orig_lp_id = 0
AND exe_cours_id = '$course_code'
AND orig_lp_item_id = 0
ORDER BY exe_date DESC";
$res = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_array($res);
$quiz_avg_score = 0;
if (!empty($row['avg_score'])) {
$quiz_avg_score = round($row['avg_score'],2);
}
$count_attempt = Database::fetch_row(Database::query("SELECT count(*) FROM $tbl_stats_exercise WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1) $condition_user AND orig_lp_id = 0 AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 ORDER BY exe_date DESC",__FILE__,__LINE__));
$lp_view_id = Database::result($rs_last_lp_view_id,0,'id'); // THE view
if ($lp_view_id != '') {
if (!empty($count_row_lp[0]) && !empty($student_id)) {
$condition_user1 = "";
if (is_array($student_id)) {
$condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
} else {
$condition_user1 =" AND user_id = '$student_id' ";
}
$sql = "SELECT max(id) as id, lp_id, user_id FROM $lp_view_table WHERE lp_id IN (SELECT id FROM $lp_table $condition_lp) $condition_user1 GROUP BY lp_id,user_id";
// Real max score - this was implemented because of the random exercises
$sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$a_learnpath['id'].'" AND orig_lp_item_id = "'.$item['item_id'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
// Real max score - this was implemented because of the random exercises
$sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$lp_item_id.'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
$sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'
UNION DISTINCT SELECT id_user as user_id FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code'";
$rs = Database::query($sql, __FILE__, __LINE__);
$users = array();
while ($row = Database::fetch_array($rs)) {
$users[] = $row['user_id'];
}
if (count($users) > 0) {
// get columns data for courses list
$sql = "SELECT count(prop.tool) as count_assignments,
count(post.poster_id) as count_messages,
(SELECT SUM(UNIX_TIMESTAMP(logout_course_date)-UNIX_TIMESTAMP(login_course_date)) FROM $tbl_track_cours_access track_course WHERE track_course.user_id = course_rel_user.user_id AND track_course.course_code='$course_code') as time_espent
FROM $tbl_course_user course_rel_user
LEFT JOIN $tbl_item_property prop ON prop.insert_user_id = course_rel_user.user_id AND tool='work'
LEFT JOIN $tbl_forum_post post ON post.poster_id = course_rel_user.user_id
WHERE course_rel_user.user_id IN (".implode(',',$users).") AND course_rel_user.course_code='$course_code'";
// get all users data from a course for sortable with limit
$condition_user = "";
if (is_array($user_ids)) {
$condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") ";
} else {
$condition_user = " WHERE user.user_id = '$user_ids' ";
}
$sql = "SELECT user.user_id as col0,
user.official_code as col1,
user.lastname as col2,
user.firstname as col3,
count(item_prop.tool) as col4,
count(post.post_id) as col5,
(SELECT login_course_date FROM $tbl_track_cours_access track_course WHERE track_course.user_id = user.user_id AND course_code = '$course_code' ORDER BY login_course_date DESC LIMIT 0,1) as col6,
(SELECT SUM(UNIX_TIMESTAMP(logout_course_date)-UNIX_TIMESTAMP(login_course_date)) FROM $tbl_track_cours_access track_course WHERE track_course.user_id = user.user_id AND track_course.course_code='$course_code') as col7
FROM $tbl_user as user
LEFT JOIN $tbl_item_property item_prop ON item_prop.insert_user_id = user.user_id AND item_prop.tool='work'
LEFT JOIN $tbl_forum_post post ON post.poster_id = user.user_id