diff --git a/mod/lesson/pagetypes/branchtable.php b/mod/lesson/pagetypes/branchtable.php index 5a43fceaebf..c7e4342084c 100644 --- a/mod/lesson/pagetypes/branchtable.php +++ b/mod/lesson/pagetypes/branchtable.php @@ -176,6 +176,17 @@ class lesson_page_type_branchtable extends lesson_page { $retries = 0; } + // First record this page in lesson_branch. This record may be needed by lesson_unseen_branch_jump. + $branch = new stdClass; + $branch->lessonid = $this->lesson->id; + $branch->userid = $USER->id; + $branch->pageid = $this->properties->id; + $branch->retry = $retries; + $branch->flag = $branchflag; + $branch->timeseen = time(); + $branch->nextpageid = 0; // Next page id will be set later. + $branch->id = $DB->insert_record("lesson_branch", $branch); + // this is called when jumping to random from a branch table $context = context_module::instance($PAGE->cm->id); if($newpageid == LESSON_UNSEENBRANCHPAGE) { @@ -201,16 +212,9 @@ class lesson_page_type_branchtable extends lesson_page { $newpageid = lesson_unseen_branch_jump($this->lesson, $USER->id); } - // Record this page in lesson_branch. - $branch = new stdClass; - $branch->lessonid = $this->lesson->id; - $branch->userid = $USER->id; - $branch->pageid = $this->properties->id; - $branch->retry = $retries; - $branch->flag = $branchflag; - $branch->timeseen = time(); + // Update record to set nextpageid. $branch->nextpageid = $newpageid; - $DB->insert_record("lesson_branch", $branch); + $DB->update_record("lesson_branch", $branch); // This will force to redirect to the newpageid. $result->inmediatejump = true;