[svn r16820] fix bug in scores

skala
Eric Marguin 16 years ago
parent 2b82155fa5
commit 1be8566d26
  1. 17
      main/inc/lib/tracking.lib.php
  2. 109
      main/mySpace/myStudents.php

@ -298,9 +298,10 @@ class Tracking {
*
* @param User id
* @param Course id
* @param Array limit average to listed lp ids
* @return string value (number %) Which represents a round integer explain in got in 3.
*/
function get_avg_student_score($student_id, $course_code) {
function get_avg_student_score($student_id, $course_code, $lp_ids=array()) {
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
@ -309,7 +310,9 @@ class Tracking {
$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course = CourseManager :: get_course_information($course_code);
if(!empty($course['db_name']))
{
@ -320,6 +323,10 @@ class Tracking {
$lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']);
$sql_course_lp = 'SELECT id FROM '.$lp_table;
if(count($lp_ids)!=0)
{
$sql_course_lp.=' WHERE id IN ('.implode(',',$lp_ids).')';
}
$sql_result_lp = api_sql_query($sql_course_lp, __FILE__, __LINE__);
$lp_scorm_score_total = 0;
@ -449,8 +456,12 @@ class Tracking {
if($lp_scorm_weighting_total>0)
{
$pourcentageScore = round(($totalScore * 100) / $lp_scorm_weighting_total);
return $pourcentageScore;
}
return $pourcentageScore;
else
{
return null;
}
}
else
{

@ -1,4 +1,4 @@
<?php //$Id: myStudents.php 16769 2008-11-17 22:19:30Z yannoo $
<?php //$Id: myStudents.php 16820 2008-11-20 09:14:14Z elixir_inter $
/* For licensing terms, see /dokeos_license.txt */
/**
* Implements the tracking of students in the Reporting pages
@ -620,108 +620,9 @@ if(!empty($_GET['student']))
if($start_time > 0) $any_result = true;
}
//QUIZZ IN LP
//Path is the exercise id we need this to search the last attempt
$sql = 'SELECT id as item_id, path,max_score
FROM '.$t_lpi.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
AND item_type="quiz"';
$rsItems = api_sql_query($sql, __FILE__, __LINE__);
//We get the last view id of this LP
$sql='SELECT max(id) as id FROM '.$t_lpv.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($_GET['student']).'"';
$rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
$lp_view_id = 0;
if(Database::num_rows($rs_last_lp_view_id)>0)
{
$lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
if($lp_view_id > 0) $any_result = true;
}
$total_score = $total_weighting = 0;
if($lp_view_id)
{
while($item = Database :: fetch_array($rsItems, 'ASSOC'))
{
$sql = 'SELECT score as student_score
FROM '.$t_lpiv.' as lp_view_item
WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
AND lp_view_id = "'.$lp_view_id.'"';
$rsScores = api_sql_query($sql, __FILE__, __LINE__);
// Real max score we search into the stats
$sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
$num = Database :: num_rows($resultLastAttempt);
if ($num > 0){
if ($num > 1){
while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
$id_last_attempt = $rowLA[0];
}
} else {
$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";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row_max_score = Database :: fetch_array($result);
$maxscore = $row_max_score['maxscore'];
if ($maxscore=='')
{
$maxscore = $item['max_score'];
}
if (Database::num_rows($rsScores) > 0)
{
$total_score += Database::result($rsScores, 0, 0);
}
//$total_weighting += $item['max_score'];
$total_weighting += $maxscore;
}
$any_result = true;
}
$sql = 'SELECT id, max_score
FROM '.$t_lpi.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
AND item_type="sco" LIMIT 1';
$rs_lp_item_id_scorm = api_sql_query($sql, __FILE__, __LINE__);
if(Database::num_rows($rs_lp_item_id_scorm)>0){
$lp_item_id = Database::result($rs_lp_item_id_scorm,0,'id');
$lp_item__max_score = Database::result($rs_lp_item_id_scorm,0,'max_score');
$total_weighting+=$lp_item__max_score;
//We get the last view id of this LP
$sql='SELECT max(id) as id FROM '.$t_lpv.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($_GET['student']).'"';
$rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
$lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
// this will get the FINAL SCORE
$sql='SELECT SUM(score)/count(lp_item_id) as score FROM '.$t_lpiv.' WHERE lp_view_id="'.$lp_view_id.'" GROUP BY lp_view_id';
$rs_score = api_sql_query($sql, __FILE__, __LINE__);
if(Database::num_rows($rs_score)>0)
{
$lp_scorm_score = Database::result($rs_score,0,'score');
$total_score+=$lp_scorm_score;
$any_result = true;
}
}
$score = 0;
if($total_weighting != 0)
{
$score = round($total_score / $total_weighting * 100,2);
}
//QUIZZ IN LP
$score = Tracking::get_avg_student_score(intval($_GET['student']), Database::escape_string($_GET['course']), array($a_learnpath['id']));
if($i%2==0){
$s_css_class="row_odd";
@ -743,7 +644,7 @@ if(!empty($_GET['student']))
<?php echo api_time_to_hms($total_time) ?>
</td>
<td align="right">
<?php echo $total_weighting>0 ? $score.'%' : '-' ?>
<?php if(!is_null($score)) echo $score.' %'; else echo '-'; ?>
</td>
<td align="right">
<?php echo $progress ?>

Loading…
Cancel
Save