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