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

@ -3117,16 +3117,23 @@ class lesson extends lesson_base {
* @param int $pageid the given page id
* @param mod_lesson_renderer $lessonoutput the lesson output rendered
* @param bool $reviewmode whether we are in review mode or not
* @param bool $redirect Optional, default to true. Set to false to avoid redirection and return the page to redirect.
* @return array the page object and contents
* @throws moodle_exception
* @since Moodle 3.3
*/
public function prepare_page_and_contents($pageid, $lessonoutput, $reviewmode) {
public function prepare_page_and_contents($pageid, $lessonoutput, $reviewmode, $redirect = true) {
global $USER, $CFG;
$page = $this->load_page($pageid);
// Check if the page is of a special type and if so take any nessecary action.
$newpageid = $page->callback_on_view($this->can_manage());
$newpageid = $page->callback_on_view($this->can_manage(), $redirect);
// Avoid redirections returning the jump to special page id.
if (!$redirect && is_numeric($newpageid) && $newpageid < 0) {
return array($newpageid, null, null);
}
if (is_numeric($newpageid)) {
$page = $this->load_page($newpageid);
}
@ -3167,7 +3174,7 @@ class lesson extends lesson_base {
ob_end_clean();
}
return array($page, $lessoncontent);
return array($page->id, $page, $lessoncontent);
}
/**
@ -4155,9 +4162,10 @@ abstract class lesson_page extends lesson_base {
* is viewed
*
* @param bool $canmanage True if the user has the manage cap
* @param bool $redirect Optional, default to true. Set to false to avoid redirection and return the page to redirect.
* @return mixed
*/
public function callback_on_view($canmanage) {
public function callback_on_view($canmanage, $redirect = true) {
return true;
}