From 2ce9628484fe9b298ec7b2e89ff1f68def71f4d9 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Wed, 5 Oct 2016 19:16:33 +0800 Subject: [PATCH] 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. --- mod/quiz/lang/en/quiz.php | 1 + mod/quiz/mod_form.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index eec5160c62e..7f25273fc74 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -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 {$a->cur}/{$a->max}.'; $string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.'; diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index abe9b980004..74029fb5816 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -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'); + } } }