From 78681d03b0afcf18b662f63fff98f38bc77fec90 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 19 Apr 2017 17:43:21 +0200 Subject: [PATCH] MDL-58431 mod_lesson: Fix error in random jumps on first visit Random jumps to content pages were not working when they were set in the first page. This was caused because the page where the jump was, was not being marked as visited before calculating the jump. --- mod/lesson/pagetypes/branchtable.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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;