// Init local variables that will be used through the calculation
$lp_scorm_result_score_total = 0;
$progress = 0;
$progress = 0;
// prepare filter on users
$condition_user1 = "";
@ -588,32 +591,33 @@ class Tracking {
array_walk($student_id,'intval');
$condition_user1 =" AND user_id IN (".implode(',',$student_id).") ";
} else {
$condition_user1 =" AND user_id = '$student_id' ";
$condition_user1 =" AND user_id = $student_id ";
}
if ($count_row_lp > 0 && !empty($student_id)) {
// Getting latest LP result for a student
// Getting latest LP result for a student
//@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
WHERE lp_id IN (".implode(',',$lp_list).") $condition_user1 AND session_id = $session_id GROUP BY lp_id, user_id";
//var_dump($sql);
if ($debug) var_dump($sql);
$rs_last_lp_view_id = Database::query($sql);
$global_count_item = 0;
$global_result = 0;
$list = array();
if (Database::num_rows($rs_last_lp_view_id) > 0) {
// Cycle through each line of the results (grouped by lp_id, user_id)
$exe_list = array();
while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) {
$count_items = 0;
$lp_partial_total = 0;
$list = array();
$lp_view_id = $row_lp_view['id'];
$progress = $row_lp_view['progress'];
$lp_id = $row_lp_view['lp_id'];
$user_id = $row_lp_view['user_id'];
//Getting
if ($debug) echo '<h2>'.$lp_id.'</h2>';
if ($get_only_latest_attempt_results) {
//if (1) {
@ -625,12 +629,11 @@ class Tracking {
$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
$sql = "SELECT lp_iv.id as lp_item_view_id, 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;
}
@ -638,10 +641,10 @@ class Tracking {
} 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
$sql_max_score = "SELECT lp_iv.id as lp_item_view_id, 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/>';
if ($debug) echo $sql_max_score.'<br/>';
$res_max_score = Database::query($sql_max_score);
@ -649,22 +652,21 @@ class Tracking {
$list[]= $row_max_score;
}
}
//var_dump($list);
$count_total_loop = 0;
// Go through each scorable element of this view
$count_items = 0;
$lp_partial_total = 0;
$score_of_scorm_calculate = 0;
foreach ($list as $row_max_score) {
$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
$score = $row_max_score['score'];
if ($debug) var_dump($row_max_score['item_type']);
if ($row_max_score['item_type'] == 'sco') {
//var_dump($row_max_score);
// Check if it is sco (easier to get max_score)
//when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100.
$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_item_id = $item_id AND exe_cours_id = '$course_code' AND session_id = $session_id
ORDER BY exe_date DESC limit 1";
$sql_last_attempt = "SELECT exe_id FROM $tbl_stats_exercices WHERE