// Init local variables that will be used through the calculation
// Init local variables that will be used through the calculation
$lp_scorm_score_total = 0;
$lp_scorm_result_score_total = 0;
$lp_scorm_result_score_total = 0;
$progress = 0;
$lp_scorm_loop=0;
$lp_count = 0;
$progress = 0;
// prepare filter on users
// prepare filter on users
$condition_user1 = "";
$condition_user1 = "";
if (is_array($student_id)) {
if (is_array($student_id)) {
array_walk($student_id,'intval');
array_walk($student_id,'intval');
$condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
$condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
@ -593,17 +589,19 @@ class Tracking {
$condition_user1 =" AND user_id = '$student_id' ";
$condition_user1 =" AND user_id = '$student_id' ";
}
}
if ($count_row_lp>0 && !empty($student_id)) {
if ($count_row_lp>0 && !empty($student_id)) {
// Get all views through learning paths filter
// Getting latest LP result for a student
//@todo problem when a course have more than 1500 users
//@todo problem when a course have more than 1500 users
$sql = "SELECT MAX(view_count) as vc, id, progress, lp_id, user_id FROM $lp_view_table ".
$sql = "SELECT MAX(view_count) as vc, id, progress, lp_id, user_id FROM $lp_view_table
"WHERE lp_id IN (".implode(',',$lp_list).") $condition_user1 AND session_id= $session_id GROUP BY lp_id,user_id";
WHERE lp_id IN (".implode(',',$lp_list).") $condition_user1 AND session_id= $session_id GROUP BY lp_id,user_id";
//var_dump($sql);
//var_dump($sql);
$rs_last_lp_view_id = Database::query($sql);
$rs_last_lp_view_id = Database::query($sql);
$global_count_item = 0;
$global_count_item = 0;
$global_result = 0;
$global_result = 0;
$list = array();
if (Database::num_rows($rs_last_lp_view_id) > 0) {
if (Database::num_rows($rs_last_lp_view_id) > 0) {
// Cycle through each line of the results (grouped by lp_id, user_id)
// Cycle through each line of the results (grouped by lp_id, user_id)
while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
@ -612,26 +610,53 @@ class Tracking {
$progress = $row_lp_view['progress'];
$progress = $row_lp_view['progress'];
$lp_id = $row_lp_view['lp_id'];
$lp_id = $row_lp_view['lp_id'];
$user_id = $row_lp_view['user_id'];
$user_id = $row_lp_view['user_id'];
// For the currently analysed view, get the score and
//Getting
// max_score of each item if it is a sco or a TOOL_QUIZ
$sql_max_score = "SELECT lp_iv.score as score,lp_i.max_score, lp_iv.max_score as max_score_item_view, lp_i.path, lp_i.item_type, lp_i.id as iid".
if ($get_only_latest_attempt_results) {
" FROM $lp_item_view_table as lp_iv INNER JOIN $lp_item_table as lp_i ".
//if (1) {
" ON lp_i.id = lp_iv.lp_item_id ".
//Getting lp_items done by the user
" AND (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') ".
$sql = "SELECT DISTINCT lp_item_id FROM $lp_item_view_table WHERE lp_view_id = $lp_view_id ORDER BY lp_item_id";
" WHERE lp_view_id='$lp_view_id'";
$res_lp_item = Database::query($sql);
//echo $sql_max_score; echo '<br/>';
while ($row_lp_item = Database::fetch_array($res_lp_item,'ASSOC')) {
$res_max_score = Database::query($sql_max_score);
$my_lp_item_id = $row_lp_item['lp_item_id'];
//Getting the most recent attempt
$sql = "SELECT lp_iv.score as score,lp_i.max_score, lp_iv.max_score as max_score_item_view, lp_i.path, lp_i.item_type, lp_i.id as iid
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 AND (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
WHERE lp_item_id = $my_lp_item_id AND lp_view_id = $lp_view_id ORDER BY view_count DESC LIMIT 1";
$res_lp_item_result = Database::query($sql);
while ($row_max_score = Database::fetch_array($res_lp_item_result,'ASSOC')) {
$list[]= $row_max_score;
}
}
} else {
// For the currently analysed view, get the score and
// max_score of each item if it is a sco or a TOOL_QUIZ
$sql_max_score = "SELECT lp_iv.score as score,lp_i.max_score, lp_iv.max_score as max_score_item_view, lp_i.path, lp_i.item_type, lp_i.id as iid
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 AND (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
WHERE lp_view_id = $lp_view_id ";
//echo $sql_max_score; echo '<br/>';
$res_max_score = Database::query($sql_max_score);
while ($row_max_score = Database::fetch_array($res_max_score,'ASSOC')) {
while ($row_max_score = Database::fetch_array($res_max_score,'ASSOC')) {
foreach ($list as $row_max_score) {
$max_score = $row_max_score['max_score']; //Came from the original lp_item
$max_score = $row_max_score['max_score']; //Came from the original lp_item
$max_score_item_view = $row_max_score['max_score_item_view']; //Came from the lp_item_view
$max_score_item_view = $row_max_score['max_score_item_view']; //Came from the lp_item_view
$score = $row_max_score['score'];
$score = $row_max_score['score'];
@ -663,13 +688,9 @@ class Tracking {
$item_path = $row_max_score['path'];
$item_path = $row_max_score['path'];
// Get last attempt to this exercise through
// Get last attempt to this exercise through
// the current lp for the current user
// the current lp for the current user
$sql_last_attempt = "SELECT exe_id FROM $tbl_stats_exercices ".
$sql_last_attempt = "SELECT exe_id FROM $tbl_stats_exercices
" WHERE exe_exo_id = '$item_path' ".
WHERE exe_exo_id = '$item_path' AND exe_user_id = $user_id AND orig_lp_item_id = $item_id AND exe_cours_id = '$course_code' AND session_id = $session_id
" AND exe_user_id = '$user_id' ".
ORDER BY exe_date DESC limit 1";
// " AND orig_lp_id = '$lp_id' ". //lp_id is already defined by the item_id
" AND orig_lp_item_id = '$item_id' ".
" AND exe_cours_id = '$course_code' AND session_id = $session_id".
@ -120,11 +120,10 @@ if (isset($_GET['lp_id']) && isset($_GET['my_lp_id'])) {
if (Database::num_rows($res_path) > 0) {
if (Database::num_rows($res_path) > 0) {
if ($origin != 'tracking') {
if ($origin != 'tracking') {
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . (int)api_get_user_id() . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';
} else {
} else {
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';