public function redirect_to_first_answer($canmanage) { global $USER, $PAGE; $answer = array_shift($this->get_answers()); $jumpto = $answer->jumpto; if ($jumpto == LESSON_RANDOMBRANCH) { $jumpto = lesson_unseen_branch_jump($this->lesson, $USER->id); } elseif ($jumpto == LESSON_CLUSTERJUMP) { if (!$canmanage) { $jumpto = $this->lesson->cluster_jump($this->properties->id); } else { if ($this->properties->nextpageid == 0) { $jumpto = LESSON_EOL; } else { $jumpto = $this->properties->nextpageid; } } } else if ($answer->jumpto == LESSON_NEXTPAGE) { if ($this->properties->nextpageid == 0) { $jumpto = LESSON_EOL; } else { $jumpto = $this->properties->nextpageid; } } else if ($jumpto == 0) { $jumpto = $this->properties->id; } else if ($jumpto == LESSON_PREVIOUSPAGE) { $jumpto = $this->properties->prevpageid; } redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$jumpto))); }
} } // convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $pageid; } elseif ($newpageid == LESSON_NEXTPAGE) { if (!($newpageid = $page->nextpageid)) { // no nextpage go to end of lesson $newpageid = LESSON_EOL; } } elseif ($newpageid == LESSON_PREVIOUSPAGE) { $newpageid = $page->prevpageid; } elseif ($newpageid == LESSON_RANDOMPAGE) { $newpageid = lesson_random_question_jump($lesson->id, $pageid); } elseif ($newpageid == LESSON_RANDOMBRANCH) { $newpageid = lesson_unseen_branch_jump($lesson->id, $USER->id); } // no need to record anything in lesson_attempts redirect("{$CFG->wwwroot}/mod/lesson/view.php?id={$cm->id}&pageid={$newpageid}"); break; } $attemptsremaining = 0; $maxattemptsreached = 0; if ($noanswer) { $newpageid = $pageid; // display same page again } else { $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (!has_capability('mod/lesson:manage', $context)) { // record student's attempt $attempt = new stdClass();
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))); }
// Check for endofclusters if ($page->nextpageid == 0) { $nextpageid = LESSON_EOL; } else { $nextpageid = $page->nextpageid; } redirect("{$CFG->wwwroot}/mod/lesson/view.php?id={$cm->id}&pageid={$nextpageid}"); } else { if ($page->qtype == LESSON_ENDOFBRANCH) { // Check for endofbranches if ($answers = get_records('lesson_answers', 'pageid', $page->id, 'id')) { // print_heading(get_string('endofbranch', 'lesson')); foreach ($answers as $answer) { // just need the first answer if ($answer->jumpto == LESSON_RANDOMBRANCH) { $answer->jumpto = lesson_unseen_branch_jump($lesson->id, $USER->id); } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { if (!has_capability('mod/lesson:manage', $context)) { $answer->jumpto = lesson_cluster_jump($lesson->id, $USER->id, $pageid); } else { if ($page->nextpageid == 0) { $answer->jumpto = LESSON_EOL; } else { $answer->jumpto = $page->nextpageid; } } } else { if ($answer->jumpto == LESSON_NEXTPAGE) { if ($page->nextpageid == 0) { $answer->jumpto = LESSON_EOL; } else {