Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-38664 Lesson mod: code improvement for lesson re-attempt page

  • Loading branch information...
commit af11bd26b6443b36456b7fb3fcfd2e496d9464d8 1 parent b8aa36a
@rwijaya rwijaya authored
Showing with 16 additions and 16 deletions.
  1. +16 −16 mod/lesson/view.php
View
32 mod/lesson/view.php
@@ -191,33 +191,33 @@
unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing
}
- // If there are any questions that have been answered correctly (or not) in this attempt
- $corrrectattempts = $lesson->get_attempts($retries);
- if (!empty($corrrectattempts)) {
- $attempt = end($corrrectattempts);
+ // If there are any questions that have been answered correctly (or not) in this attempt.
+ $allattempts = $lesson->get_attempts($retries);
+ if (!empty($allattempts)) {
+ $attempt = end($allattempts);
+ $attemptpage = $lesson->load_page($attempt->pageid);
$jumpto = $DB->get_field('lesson_answers', 'jumpto', array('id' => $attempt->answerid));
// convert the jumpto to a proper page id
- if ($jumpto == 0) { // unlikely value! except in JR mod
- // Check if a question has been incorrectly answered AND no more attempts at it are left
- $nattempts = $DB->count_records("lesson_attempts", array("pageid" => $attempt->pageid, "userid" => $USER->id, "retry" => $attempt->retry));
- if ($nattempts >= $lesson->maxattempts) {
- $lastpageseen = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $attempt->pageid));
+ if ($jumpto == 0) {
+ // Check if a question has been incorrectly answered AND no more attempts at it are left.
+ $nattempts = $lesson->get_attempts($attempt->retry, false, $attempt->pageid, $USER->id);
+ if (count($nattempts) >= $lesson->maxattempts) {
+ $lastpageseen = $lesson->get_next_page($attemptpage->nextpageid);
+ } else {
+ $lastpageseen = $attempt->pageid;
}
} elseif ($jumpto == LESSON_NEXTPAGE) {
- if (!$lastpageseen = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $attempt->pageid))) {
- // no nextpage go to end of lesson
- $lastpageseen = LESSON_EOL;
- }
+ $lastpageseen = $lesson->get_next_page($attemptpage->nextpageid);
} else {
$lastpageseen = $jumpto;
}
}
- if ($branchtables = $DB->get_records('lesson_branch', array("lessonid"=>$lesson->id, "userid"=>$USER->id, "retry"=>$retries), 'timeseen DESC')) {
+ if ($branchtables = $DB->get_records('lesson_branch', array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $retries), 'timeseen DESC')) {
// in here, user has viewed a branch table
$lastbranchtable = current($branchtables);
- if (count($corrrectattempts)>0) {
- foreach($corrrectattempts as $attempt) {
+ if (count($allattempts) > 0) {
+ foreach($allattempts as $attempt) {
if ($lastbranchtable->timeseen > $attempt->timeseen) {
// branch table was viewed later than the last attempt
$lastpageseen = $lastbranchtable->pageid;
Please sign in to comment.
Something went wrong with that request. Please try again.