Skip to content

Commit

Permalink
It seems that grades are saved with two decimal points of precision w…
Browse files Browse the repository at this point in the history
…hile

they are being retrieved as integers. Changed it to two decimals everywhere
and continuing to go about it...
  • Loading branch information
defacer committed Jan 27, 2005
1 parent cb8057d commit 35f45a0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mod/quiz/locallib.php
Expand Up @@ -1444,35 +1444,35 @@ function quiz_get_best_grade($quizid, $userid) {
return NULL;
}

return (round($grade->grade));
return (round($grade->grade, 2));
}

function quiz_save_best_grade($quiz, $userid) {
/// Calculates the best grade out of all attempts at a quiz for a user,
/// and then saves that grade in the quiz_grades table.

if (!$attempts = quiz_get_user_attempts($quiz->id, $userid)) {
notify("Could not find any user attempts");
notify('Could not find any user attempts');
return false;
}

$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = (($bestgrade / $quiz->sumgrades) * $quiz->grade);

if ($grade = get_record("quiz_grades", "quiz", $quiz->id, "userid", $userid)) {
if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
$grade->grade = round($bestgrade, 2);
$grade->timemodified = time();
if (!update_record("quiz_grades", $grade)) {
notify("Could not update best grade");
if (!update_record('quiz_grades', $grade)) {
notify('Could not update best grade');
return false;
}
} else {
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = round($bestgrade, 2);
$grade->timemodified = time();
if (!insert_record("quiz_grades", $grade)) {
notify("Could not insert new best grade");
if (!insert_record('quiz_grades', $grade)) {
notify('Could not insert new best grade');
return false;
}
}
Expand Down

0 comments on commit 35f45a0

Please sign in to comment.