MDL-58415 mod_lesson: Avoid API http redirections

Deep in the lesson API there are some http redirections in special
pages like clusters.
We need to handle it via new parameters to avoid redirections.
This commit is contained in:
Juan Leyva 2017-03-28 10:58:52 +02:00
parent 16ca026c4b
commit 0259109fb5
7 changed files with 78 additions and 54 deletions

View file

@ -55,14 +55,14 @@ class lesson_page_type_cluster extends lesson_page {
public function get_grayout() {
return 1;
}
public function callback_on_view($canmanage) {
public function callback_on_view($canmanage, $redirect = true) {
global $USER;
if (!$canmanage) {
// Get the next page in the lesson cluster jump
return $this->lesson->cluster_jump($this->properties->id);
return (int) $this->lesson->cluster_jump($this->properties->id);
} else {
// get the next page
return $this->properties->nextpageid;
return (int) $this->properties->nextpageid;
}
}
public function override_next_page() {

View file

@ -51,12 +51,11 @@ class lesson_page_type_endofbranch extends lesson_page {
public function get_idstring() {
return $this->typeidstring;
}
public function callback_on_view($canmanage) {
$this->redirect_to_first_answer($canmanage);
exit;
public function callback_on_view($canmanage, $redirect = true) {
return (int) $this->redirect_to_first_answer($canmanage, $redirect);
}
public function redirect_to_first_answer($canmanage) {
public function redirect_to_first_answer($canmanage, $redirect) {
global $USER, $PAGE;
$answers = $this->get_answers();
$answer = array_shift($answers);
@ -94,7 +93,12 @@ class lesson_page_type_endofbranch extends lesson_page {
$jumpto = $this->properties->prevpageid;
}
redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$jumpto)));
if ($redirect) {
redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $jumpto)));
die;
}
return $jumpto;
}
public function get_grayout() {
return 1;

View file

@ -51,18 +51,21 @@ class lesson_page_type_endofcluster extends lesson_page {
public function get_idstring() {
return $this->typeidstring;
}
public function callback_on_view($canmanage) {
$this->redirect_to_next_page($canmanage);
exit;
public function callback_on_view($canmanage, $redirect = true) {
return (int) $this->redirect_to_next_page($canmanage, $redirect);
}
public function redirect_to_next_page() {
public function redirect_to_next_page($canmanage, $redirect) {
global $PAGE;
if ($this->properties->nextpageid == 0) {
$nextpageid = LESSON_EOL;
} else {
$nextpageid = $this->properties->nextpageid;
}
redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$nextpageid)));
if ($redirect) {
redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $nextpageid)));
die;
}
return $nextpageid;
}
public function get_grayout() {
return 1;