From 0aec842e5884ceb560b4fa3d1921c6ce2d06efa8 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Thu, 24 Apr 2014 10:14:13 +0800 Subject: [PATCH] MDL-45127 mod_lesson: Fixed reviewing lesson answers changing the lesson grade. --- mod/lesson/continue.php | 2 ++ mod/lesson/locallib.php | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/lesson/continue.php b/mod/lesson/continue.php index 9144edc6c9b..9106cfb7f7a 100644 --- a/mod/lesson/continue.php +++ b/mod/lesson/continue.php @@ -94,6 +94,8 @@ if (isset($USER->modattempts[$lesson->id])) { $attempts = $DB->get_records("lesson_attempts", array("lessonid"=>$lesson->id, "userid"=>$USER->id, "retry"=>$nretakes), "timeseen", "id, pageid"); $found = false; $temppageid = 0; + // Make sure that the newpageid always defaults to something valid. + $result->newpageid = LESSON_EOL; foreach($attempts as $attempt) { if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page $result->newpageid = $attempt->pageid; diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index b790693ea7f..042beac2ec5 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -1989,12 +1989,17 @@ abstract class lesson_page extends lesson_base { $attempt->timeseen = time(); // if allow modattempts, then update the old attempt record, otherwise, insert new answer record + $userisreviewing = false; if (isset($USER->modattempts[$this->lesson->id])) { $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high + $userisreviewing = true; } - if ($this->lesson->retake || (!$this->lesson->retake && $nretakes == 0)) { - $DB->insert_record("lesson_attempts", $attempt); + // Only insert a record if we are not reviewing the lesson. + if (!$userisreviewing) { + if ($this->lesson->retake || (!$this->lesson->retake && $nretakes == 0)) { + $DB->insert_record("lesson_attempts", $attempt); + } } // "number of attempts remaining" message if $this->lesson->maxattempts > 1 // displaying of message(s) is at the end of page for more ergonomic display