Merge branch 'MDL-28226' of git://github.com/timhunt/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-08-23 01:42:05 +02:00
commit c04b098343

View file

@ -544,25 +544,21 @@ function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) {
/** /**
* Calculate the overall grade for a quiz given a number of attempts by a particular user. * Calculate the overall grade for a quiz given a number of attempts by a particular user.
* *
* @return float The overall grade * @param object $quiz the quiz settings object.
* @param object $quiz The quiz for which the best grade is to be calculated * @param array $attempts an array of all the user's attempts at this quiz in order.
* @param array $attempts An array of all the attempts of the user at the quiz * @return float the overall grade
*/ */
function quiz_calculate_best_grade($quiz, $attempts) { function quiz_calculate_best_grade($quiz, $attempts) {
switch ($quiz->grademethod) { switch ($quiz->grademethod) {
case QUIZ_ATTEMPTFIRST: case QUIZ_ATTEMPTFIRST:
foreach ($attempts as $attempt) { $firstattempt = reset($attempts);
return $attempt->sumgrades; return $firstattempt->sumgrades;
}
return $final;
case QUIZ_ATTEMPTLAST: case QUIZ_ATTEMPTLAST:
foreach ($attempts as $attempt) { $lastattempt = end($attempts);
$final = $attempt->sumgrades; return $lastattempt->sumgrades;
}
return $final;
case QUIZ_GRADEAVERAGE: case QUIZ_GRADEAVERAGE:
$sum = 0; $sum = 0;
@ -578,8 +574,8 @@ function quiz_calculate_best_grade($quiz, $attempts) {
} }
return $sum / $count; return $sum / $count;
default:
case QUIZ_GRADEHIGHEST: case QUIZ_GRADEHIGHEST:
default:
$max = null; $max = null;
foreach ($attempts as $attempt) { foreach ($attempts as $attempt) {
if ($attempt->sumgrades > $max) { if ($attempt->sumgrades > $max) {