Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-38664 Lesson mod: code improvement for lesson attemps

  • Loading branch information...
commit eea9ffd5518729d605cecad85c92eb698d7861a5 1 parent 21c314d
@rwijaya rwijaya authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 mod/lesson/view.php
View
16 mod/lesson/view.php
@@ -192,16 +192,18 @@
}
// 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);
+ $allattempts = $lesson->get_attempts($retries);
+ if (!empty($allattempts)) {
+ $attempt = end($allattempts);
$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
+ if ($jumpto == 0) {
// 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));
+ } else {
+ $lastpageseen = $attempt->pageid;
}
} elseif ($jumpto == LESSON_NEXTPAGE) {
if (!$lastpageseen = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $attempt->pageid))) {
@@ -213,11 +215,11 @@
}
}
- 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.