} if (!empty($errors)) { // print out the errors if any echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('completethefollowingconditions', 'lesson', format_string($lesson->name))); echo $lessonoutput->dependancy_errors($dependentlesson, $errors); echo $lessonoutput->footer(); exit; } } } } } } // this is called if a student leaves during a lesson if ($pageid == LESSON_UNSEENBRANCHPAGE) { $pageid = lesson_unseen_question_jump($lesson, $USER->id, $pageid); } // display individual pages and their sets of answers // if pageid is EOL then the end of the lesson has been reached // for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down $attemptflag = false; if (empty($pageid)) { // make sure there are pages to view if (!$DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { if (!$canmanage) { $lesson->add_message(get_string('lessonnotready2', 'lesson')); // a nice message to the student } else { if (!$DB->count_records('lesson_pages', array('lessonid' => $lesson->id))) { redirect("{$CFG->wwwroot}/mod/lesson/edit.php?id={$cm->id}"); // no pages - redirect to add pages
} elseif ($result->newpageid != LESSON_CLUSTERJUMP && $page->id != 0 && $result->newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. // If so, dont display, go into the cluster. The $result->newpageid > 0 is used to filter out all of the negative code jumps. $newpage = $lesson->load_page($result->newpageid); if ($newpageid = $newpage->override_next_page($result->newpageid)) { $result->newpageid = $newpageid; } } elseif ($result->newpageid == LESSON_UNSEENBRANCHPAGE) { if ($canmanage) { if ($page->nextpageid == 0) { $result->newpageid = LESSON_EOL; } else { $result->newpageid = $page->nextpageid; } } else { $result->newpageid = lesson_unseen_question_jump($lesson, $USER->id, $page->id); } } elseif ($result->newpageid == LESSON_PREVIOUSPAGE) { $result->newpageid = $page->prevpageid; } elseif ($result->newpageid == LESSON_RANDOMPAGE) { $result->newpageid = lesson_random_question_jump($lesson, $page->id); } elseif ($result->newpageid == LESSON_CLUSTERJUMP) { if ($canmanage) { if ($page->nextpageid == 0) { // if teacher, go to next page $result->newpageid = LESSON_EOL; } else { $result->newpageid = $page->nextpageid; } } else { $result->newpageid = $lesson->cluster_jump($page->id);
public function check_answer() { global $USER, $DB, $PAGE, $CFG; require_sesskey(); $newpageid = optional_param('jumpto', NULL, PARAM_INT); // going to insert into lesson_branch if ($newpageid == LESSON_RANDOMBRANCH) { $branchflag = 1; } else { $branchflag = 0; } if ($grades = $DB->get_records("lesson_grades", array("lessonid" => $this->lesson->id, "userid" => $USER->id), "grade DESC")) { $retries = count($grades); } else { $retries = 0; } $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(); $DB->insert_record("lesson_branch", $branch); // this is called when jumping to random from a branch table $context = get_context_instance(CONTEXT_MODULE, $PAGE->cm->id); if($newpageid == LESSON_UNSEENBRANCHPAGE) { if (has_capability('mod/lesson:manage', $context)) { $newpageid = LESSON_NEXTPAGE; } else { $newpageid = lesson_unseen_question_jump($this->lesson, $USER->id, $this->properties->id); // this may return 0 } } // convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $this->properties->id; } elseif ($newpageid == LESSON_NEXTPAGE) { if (!$newpageid = $this->nextpageid) { // no nextpage go to end of lesson $newpageid = LESSON_EOL; } } elseif ($newpageid == LESSON_PREVIOUSPAGE) { $newpageid = $this->prevpageid; } elseif ($newpageid == LESSON_RANDOMPAGE) { $newpageid = lesson_random_question_jump($this->lesson, $this->properties->id); } elseif ($newpageid == LESSON_RANDOMBRANCH) { $newpageid = lesson_unseen_branch_jump($this->lesson, $USER->id); } // no need to record anything in lesson_attempts redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$newpageid))); }