diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index baff7de855..5f84b3b295 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -336,8 +336,7 @@ class Tracking { //We get the last view id of this LP $sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__); - $lp_view_id = Database::result($rs_last_lp_view_id,0,'id'); - + $lp_view_id = Database::result($rs_last_lp_view_id,0,'id'); $sql='SELECT SUM(lp_iv.score)/count(lp_item_id) as score, SUM(lp_iv.max_score)/count(lp_item_id) as max_score FROM '.$lp_item_view_table.' as lp_iv @@ -380,17 +379,14 @@ class Tracking { $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); $total_score = $total_weighting = 0; - if($lp_view_id!=0) - { - while($item = Database :: fetch_array($rsItems, 'ASSOC')) - { + if ($lp_view_id!=0) { + while ($item = Database :: fetch_array($rsItems, 'ASSOC')) { // we take the score from a LP because we have lp_view_id $sql = 'SELECT score as student_score FROM '.$lp_item_view_table.' as lp_view_item WHERE lp_view_item.lp_item_id = '.$item['item_id'].' - AND lp_view_id = "'.$lp_view_id.'" - '; - + AND lp_view_id = "'.$lp_view_id.'" '; + $rsScores = api_sql_query($sql, __FILE__, __LINE__); // Real max score - this was implemented because of the random exercises @@ -405,36 +401,45 @@ class Tracking { $id_last_attempt = $rowLA[0]; } } else { - $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); - + $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); } - } + } + $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " . - "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t"; + "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t"; + $result = api_sql_query($sql, __FILE__, __LINE__); $row_max_score = Database :: fetch_array($result); $maxscore = $row_max_score['maxscore']; - if ($maxscore=='') - { + if ($maxscore=='') { $maxscore = $item['max_score']; } - - if(Database::num_rows($rsScores)>0) - { + // not right! + /*if(Database::num_rows($rsScores)>0) { $total_score += Database::result($rsScores, 0, 0); - //echo $total_weighting += $item['max_score']; $total_weighting += $maxscore; - if($total_weighting>0) - { - $lp_scorm_score_total += ($total_score/$total_weighting)*100; + if($total_weighting>0) { + //echo ($total_score/$total_weighting)*100; + $lp_scorm_score_total += ($total_score/$total_weighting)*100; + $lp_scorm_weighting_total+=100; + } + }*/ + + if(Database::num_rows($rsScores)>0) { + $total_score = Database::result($rsScores, 0, 0); + //echo $total_weighting += $item['max_score']; + $total_weighting += $maxscore; + if($total_weighting>0) { + //echo $total_score.' - '.$maxscore; echo '
'; + //echo $lp_scorm_score_total += ($total_score/$total_weighting)*100; + $lp_scorm_score_total += ($total_score/$maxscore)*100; $lp_scorm_weighting_total+=100; } } } - } - + } } } @@ -445,14 +450,10 @@ class Tracking { //i.e 10.52 $pourcentageScore = round( (($totalScore * 100) / $lp_scorm_weighting_total),2); return $pourcentageScore; - } - else - { + } else { return null; } - } - else - { + } else { return null; } }