MDL-40441 fix obscure notice in the quiz.
This can only happen if you have both a user with both a real attempt and a preview, and then edit the quiz settings. Also clean up this code a bit.
This commit is contained in:
+12
-10
@@ -106,6 +106,7 @@ function quiz_add_instance($quiz) {
|
||||
*/
|
||||
function quiz_update_instance($quiz, $mform) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
// Process the options from the form.
|
||||
$result = quiz_process_options($quiz);
|
||||
@@ -113,11 +114,16 @@ function quiz_update_instance($quiz, $mform) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Get the current value, so we can see what changed.
|
||||
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));
|
||||
|
||||
// We need two values from the existing DB record that are not in the form,
|
||||
// in some of the function calls below.
|
||||
$quiz->sumgrades = $oldquiz->sumgrades;
|
||||
$quiz->grade = $oldquiz->grade;
|
||||
|
||||
// Repaginate, if asked to.
|
||||
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true),
|
||||
$quiz->questionsperpage);
|
||||
}
|
||||
@@ -131,19 +137,15 @@ function quiz_update_instance($quiz, $mform) {
|
||||
quiz_after_add_or_update($quiz);
|
||||
|
||||
if ($oldquiz->grademethod != $quiz->grademethod) {
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
$quiz->sumgrades = $oldquiz->sumgrades;
|
||||
$quiz->grade = $oldquiz->grade;
|
||||
quiz_update_all_final_grades($quiz);
|
||||
quiz_update_grades($quiz);
|
||||
}
|
||||
|
||||
$updateattempts = $oldquiz->timelimit != $quiz->timelimit
|
||||
|| $oldquiz->timeclose != $quiz->timeclose
|
||||
|| $oldquiz->graceperiod != $quiz->graceperiod;
|
||||
if ($updateattempts) {
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
quiz_update_open_attempts(array('quizid'=>$quiz->id));
|
||||
$quizdateschanged = $oldquiz->timelimit != $quiz->timelimit
|
||||
|| $oldquiz->timeclose != $quiz->timeclose
|
||||
|| $oldquiz->graceperiod != $quiz->graceperiod;
|
||||
if ($quizdateschanged) {
|
||||
quiz_update_open_attempts(array('quizid' => $quiz->id));
|
||||
}
|
||||
|
||||
// Delete any previous preview attempts.
|
||||
|
||||
Reference in New Issue
Block a user