MDL-76897 quiz: deprecate unused quiz_calculate_best_attempt

This commit is contained in:
Tim Hunt
2023-02-27 18:41:58 +00:00
parent 728160cfbc
commit 20ccfc162d
3 changed files with 44 additions and 39 deletions
+43
View File
@@ -441,3 +441,46 @@ function quiz_calculate_best_grade($quiz, $attempts) {
return $max;
}
}
/**
* Return the attempt with the best grade for a quiz
*
* Which attempt is the best depends on $quiz->grademethod. If the grade
* method is GRADEAVERAGE then this function simply returns the last attempt.
* @return stdClass The attempt with the best grade
* @param stdClass $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
* @deprecated since Moodle 4.2. No direct replacement.
* @todo MDL-76612 Final deprecation in Moodle 4.6
*/
function quiz_calculate_best_attempt($quiz, $attempts) {
debugging('quiz_calculate_best_attempt is deprecated with no direct replacement. ' .
'It was not used anywhere!', DEBUG_DEVELOPER);
switch ($quiz->grademethod) {
case QUIZ_ATTEMPTFIRST:
foreach ($attempts as $attempt) {
return $attempt;
}
break;
case QUIZ_GRADEAVERAGE: // We need to do something with it.
case QUIZ_ATTEMPTLAST:
foreach ($attempts as $attempt) {
$final = $attempt;
}
return $final;
default:
case QUIZ_GRADEHIGHEST:
$max = -1;
foreach ($attempts as $attempt) {
if ($attempt->sumgrades > $max) {
$max = $attempt->sumgrades;
$maxattempt = $attempt;
}
}
return $maxattempt;
}
}
-39
View File
@@ -850,45 +850,6 @@ function quiz_get_attempt_usertime_sql($redundantwhereclauses = '') {
return $quizausersql;
}
/**
* Return the attempt with the best grade for a quiz
*
* Which attempt is the best depends on $quiz->grademethod. If the grade
* method is GRADEAVERAGE then this function simply returns the last attempt.
* @return stdClass The attempt with the best grade
* @param stdClass $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
*/
function quiz_calculate_best_attempt($quiz, $attempts) {
switch ($quiz->grademethod) {
case QUIZ_ATTEMPTFIRST:
foreach ($attempts as $attempt) {
return $attempt;
}
break;
case QUIZ_GRADEAVERAGE: // We need to do something with it.
case QUIZ_ATTEMPTLAST:
foreach ($attempts as $attempt) {
$final = $attempt;
}
return $final;
default:
case QUIZ_GRADEHIGHEST:
$max = -1;
foreach ($attempts as $attempt) {
if ($attempt->sumgrades > $max) {
$max = $attempt->sumgrades;
$maxattempt = $attempt;
}
}
return $maxattempt;
}
}
/**
* @return array int => lang string the options for calculating the quiz grade
* from the individual attempt grades.
+1
View File
@@ -85,6 +85,7 @@ This files describes API changes in the quiz code.
- quiz_set_grade -> update_quiz_maximum_grade
- quiz_save_best_grade -> recompute_final_grade
- quiz_calculate_best_grade -> [no public direct replacement]
- quiz_calculate_best_attempt - [no replacement. It was not used.]
* Final deprecation (complete removal) of the following functions which were deprecated long ago:
- quiz_groups_member_added_handler - deprecated since 2.6