MDL-54802 mod_quiz: Add validation to require passing grade greater than 0

This commit adds a form validation to prevent the creation of quizzes
using zero or null grade to pass when using require passing grade.
This commit is contained in:
Simey Lameze 2016-09-21 16:09:25 +08:00
parent 1f2744851f
commit 981356b23d
4 changed files with 34 additions and 1 deletions

View file

@ -193,5 +193,30 @@ function xmldb_quiz_upgrade($oldversion) {
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016052301) {
// Find quizzes with the combination of require passing grade and grade to pass 0.
$quizzes = $DB->get_records_sql("
SELECT gi.id, gi.iteminstance
FROM {quiz} q
INNER JOIN {course_modules} cm ON q.id = cm.instance
INNER JOIN {grade_items} gi ON q.id = gi.iteminstance
WHERE q.completionpass = 1
AND gi.gradepass = 0
AND cm.completiongradeitemnumber IS NULL");
if ($quizzes) {
foreach ($quizzes as $quiz) {
$DB->execute("UPDATE {course_modules}
SET completiongradeitemnumber = :gradeitemid
WHERE instance = :quizid",
array('gradeitemid' => $quiz->id, 'quizid' => $quiz->iteminstance));
}
}
// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2016052301, 'quiz');
}
return true;
}