Verified Commit 2ce96284 authored by Cameron Ball's avatar Cameron Ball
Browse files

MDL-54802 mod_quiz: Improve validation when editing a quiz uusing require passing grade

When editing a quiz that is using the require passing grade completion method,
the grade to pass cannot be zero. Since the completion method is locked we
cannot recommend that the completion method is changed (as we do when the quiz
is being created). Instead we have to inform the user that the grade to pass
must not be zero.
parent 4f110020
......@@ -397,6 +397,7 @@ $string['grademethod_help'] = 'When multiple attempts are allowed, the following
$string['gradesdeleted'] = 'Quiz grades deleted';
$string['gradesofar'] = '{$a->method}: {$a->mygrade} / {$a->quizgrade}.';
$string['gradetopassnotset'] = 'This quiz does not have a grade to pass set so you cannot use this option. Please use the require grade setting instead.';
$string['gradetopassmustbeset'] = 'Grade to pass cannot be zero as this quiz has its completion method set to require passing grade. Please set a non-zero value.';
$string['gradingdetails'] = 'Marks for this submission: {$a->raw}/{$a->max}.';
$string['gradingdetailsadjustment'] = 'With previous penalties this gives <strong>{$a->cur}/{$a->max}</strong>.';
$string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.';
......
......@@ -534,9 +534,15 @@ class mod_quiz_mod_form extends moodleform_mod {
}
if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC) {
$completionpass = isset($data['completionpass']) ? $data['completionpass'] : $this->current->completionpass;
// Show an error if require passing grade was selected and the grade to pass was set to 0.
if ($data['completionpass'] == 1 && (empty($data['gradepass']) || grade_floatval($data['gradepass']) == 0)) {
$errors['completionpassgroup'] = get_string('gradetopassnotset', 'quiz');
if ($completionpass && (empty($data['gradepass']) || grade_floatval($data['gradepass']) == 0)) {
if (isset($data['completionpass'])) {
$errors['completionpassgroup'] = get_string('gradetopassnotset', 'quiz');
} else {
$errors['gradepass'] = get_string('gradetopassmustbeset', 'quiz');
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment