MDL-20860 quiz grades that had already been formatted for output were being used in database queries.

Which really does not work in locales that use , as a decimal point.

Also, this commit fixes one performance problem in index.php with DB queries in a loop.
This commit is contained in:
Tim Hunt
2010-05-07 00:08:16 +00:00
parent ff93c80742
commit 2b38499d60
4 changed files with 24 additions and 13 deletions
+13 -4
View File
@@ -89,6 +89,13 @@
array_push($align, 'left');
}
$showing = 'scores'; // default
$scores = $DB->get_records_sql_menu('
SELECT qg.quiz, qg.grade
FROM {quiz_grades} qg
JOIN {quiz} q ON q.id = qg.quiz
WHERE q.course = ?',
$course->id);
}
$table = new html_table();
@@ -141,18 +148,20 @@
} else if ($showing == 'scores') {
// Grade and feedback.
$bestgrade = quiz_get_best_grade($quiz, $USER->id);
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
$grade = '';
$feedback = '';
if ($quiz->grade && !is_null($bestgrade)) {
if ($quiz->grade && array_key_exists($quiz->id, $scores)) {
if ($alloptions->scores) {
$grade = "$bestgrade / $quiz->grade";
$a = new stdClass;
$a->grade = quiz_format_grade($quiz, $scores[$quiz->id]);
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
$grade = get_string('outofshort', 'quiz', $a);
}
if ($alloptions->overallfeedback) {
$feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
$feedback = quiz_feedback_for_grade($scores[$quiz->id], $quiz->id);
}
}
$data[] = $grade;
+5 -6
View File
@@ -401,8 +401,7 @@ function quiz_has_grades($quiz) {
/**
* Get the best current grade for a particular user in a quiz.
*
* @global object
* @param object $quiz the quiz object.
* @param object $quiz the quiz settings.
* @param integer $userid the id of the user.
* @return float the user's current grade for this quiz, or NULL if this user does
* not have a grade on this quiz.
@@ -412,11 +411,11 @@ function quiz_get_best_grade($quiz, $userid) {
$grade = $DB->get_field('quiz_grades', 'grade', array('quiz' => $quiz->id, 'userid' => $userid));
// Need to detect errors/no result, without catching 0 scores.
if (is_numeric($grade)) {
return quiz_format_grade($quiz, $grade);
} else {
return NULL;
if ($grade === false) {
return null;
}
return $grade + 0; // Convert to number.
}
/**
+2 -2
View File
@@ -175,7 +175,7 @@
}
/// Show scores (if the user is allowed to see scores at the moment).
$grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
$grade = quiz_rescale_grade($attempt->sumgrades, $quiz, false);
if ($options->scores) {
if (quiz_has_grades($quiz)) {
if($overtime) {
@@ -194,7 +194,7 @@
/// Now the scaled grade.
$a = new stdClass;
$a->grade = '<b>' . $grade . '</b>';
$a->grade = '<b>' . quiz_format_grade($quiz, $grade) . '</b>';
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
$a->percent = '<b>' . round(($attempt->sumgrades/$quiz->sumgrades)*100, 0) . '</b>';
$rows[] = '<tr><th scope="row" class="cell">' . get_string('grade') . '</th><td class="cell">' .
+4 -1
View File
@@ -318,7 +318,10 @@
$a->quizgrade = quiz_format_grade($quiz, $quiz->grade);
$resultinfo .= $OUTPUT->heading(get_string('gradesofar', 'quiz', $a), 2, 'main');
} else {
$a = quiz_format_grade($quiz, $mygrade) . '/' . quiz_format_grade($quiz, $quiz->grade);
$a = new stdClass;
$a->grade = quiz_format_grade($quiz, $mygrade);
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
$a = get_string('outofshort', 'quiz', $a);
$resultinfo .= $OUTPUT->heading(get_string('yourfinalgradeis', 'quiz', $a), 2, 'main');
}
}