diff --git a/mod/lesson/continue.php b/mod/lesson/continue.php index e2d683a4da6..ba5e7690ace 100644 --- a/mod/lesson/continue.php +++ b/mod/lesson/continue.php @@ -168,10 +168,6 @@ if ($canmanage) { if ($result->attemptsremaining != 0 && $lesson->review && !$reviewmode) { $lesson->add_message(get_string('attemptsremaining', 'lesson', $result->attemptsremaining)); } -// Report if max attempts reached -if ($result->maxattemptsreached != 0 && $lesson->review && !$reviewmode) { - $lesson->add_message('('.get_string("maximumnumberofattemptsreached", "lesson").')'); -} $PAGE->set_url('/mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id)); $PAGE->set_subpage($page->id); @@ -187,7 +183,7 @@ if ($lesson->displayleft) { if ($lesson->ongoing && !$reviewmode) { echo $lessonoutput->ongoing_score($lesson); } -if (!$result->maxattemptsreached && !$reviewmode) { +if (!$reviewmode) { echo $result->feedback; } diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 4985a33c194..11fcdf45963 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -2429,6 +2429,19 @@ abstract class lesson_page extends lesson_base { } else { if (!has_capability('mod/lesson:manage', $context)) { $nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$this->lesson->id, "userid"=>$USER->id)); + + // Get the number of attempts that have been made on this question for this student and retake, + $nattempts = $DB->count_records('lesson_attempts', array('lessonid' => $this->lesson->id, + 'userid' => $USER->id, 'pageid' => $this->properties->id, 'retry' => $nretakes)); + + // Check if they have reached (or exceeded) the maximum number of attempts allowed. + if ($nattempts >= $this->lesson->maxattempts) { + $result->maxattemptsreached = true; + $result->feedback = get_string('maximumnumberofattemptsreached', 'lesson'); + $result->newpageid = $this->lesson->get_next_page($this->properties->nextpageid); + return $result; + } + // record student's attempt $attempt = new stdClass; $attempt->lessonid = $this->lesson->id; @@ -2465,14 +2478,13 @@ abstract class lesson_page extends lesson_base { $event->add_record_snapshot('lesson_attempts', $attempt); $event->trigger(); + // Increase the number of attempts made. + $nattempts++; } } // "number of attempts remaining" message if $this->lesson->maxattempts > 1 // displaying of message(s) is at the end of page for more ergonomic display if (!$result->correctanswer && ($result->newpageid == 0)) { - // wrong answer and student is stuck on this page - check how many attempts - // the student has had at this page/question - $nattempts = $DB->count_records("lesson_attempts", array("pageid"=>$this->properties->id, "userid"=>$USER->id, "retry" => $attempt->retry)); // retreive the number of attempts left counter for displaying at bottom of feedback page if ($nattempts >= $this->lesson->maxattempts) { if ($this->lesson->maxattempts > 1) { // don't bother with message if only one attempt