MDL-35482 lesson: return to previous page after edit and page save

This commit is contained in:
Mohamed Alsharaf 2013-08-01 14:23:10 +12:00
parent a149d6a177
commit 324954141e
3 changed files with 42 additions and 7 deletions

View File

@ -32,6 +32,11 @@ $pageid = required_param('pageid', PARAM_INT);
$id = required_param('id', PARAM_INT); // Course Module ID
$qtype = optional_param('qtype', 0, PARAM_INT);
$edit = optional_param('edit', false, PARAM_BOOL);
$returnto = optional_param('returnto', null, PARAM_URL);
if (empty($returnto)) {
$returnto = new moodle_url('/mod/lesson/edit.php', array('id' => $id));
$returnto->set_anchor('lesson-' . $pageid);
}
$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
@ -66,17 +71,31 @@ $editoroptions = array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'max
// the Question type selection was cancelled. For this reason, a dummy form
// is created here solely to check whether the selection was cancelled.
if ($qtype) {
$mformdummy = $manager->get_page_form(0, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes));
$mformdummy = $manager->get_page_form(0, array(
'editoroptions' => $editoroptions,
'jumpto' => $jumpto,
'lesson' => $lesson,
'edit' => $edit,
'maxbytes' => $PAGE->course->maxbytes,
'returnto' => $returnto
));
if ($mformdummy->is_cancelled()) {
redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id");
redirect($returnto);
exit;
}
}
$mform = $manager->get_page_form($qtype, array('editoroptions'=>$editoroptions, 'jumpto'=>$jumpto, 'lesson'=>$lesson, 'edit'=>$edit, 'maxbytes'=>$PAGE->course->maxbytes));
$mform = $manager->get_page_form($qtype, array(
'editoroptions' => $editoroptions,
'jumpto' => $jumpto,
'lesson' => $lesson,
'edit' => $edit,
'maxbytes' => $PAGE->course->maxbytes,
'returnto' => $returnto
));
if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$id");
redirect($returnto);
exit;
}
@ -155,7 +174,7 @@ if ($data = $mform->get_data()) {
} else {
$editpage = lesson_page::create($data, $lesson, $context, $PAGE->course->maxbytes);
}
redirect(new moodle_url('/mod/lesson/edit.php', array('id'=>$cm->id)));
redirect($returnto);
}
$lessonoutput = $PAGE->get_renderer('mod_lesson');

View File

@ -577,7 +577,12 @@ function lesson_add_header_buttons($cm, $context, $extraeditbuttons=false, $less
print_error('invalidpageid', 'lesson');
}
if (!empty($lessonpageid) && $lessonpageid != LESSON_EOL) {
$url = new moodle_url('/mod/lesson/editpage.php', array('id'=>$cm->id, 'pageid'=>$lessonpageid, 'edit'=>1));
$url = new moodle_url('/mod/lesson/editpage.php', array(
'id' => $cm->id,
'pageid' => $lessonpageid,
'edit' => 1,
'returnto' => $PAGE->url->out(false)
));
$PAGE->set_button($OUTPUT->single_button($url, get_string('editpagecontent', 'lesson')));
}
}
@ -700,6 +705,11 @@ abstract class lesson_add_page_form_base extends moodleform {
$mform->addElement('header', 'qtypeheading', get_string('createaquestionpage', 'lesson', get_string($this->qtypestring, 'lesson')));
if (!empty($this->_customdata['returnto'])) {
$mform->addElement('hidden', 'returnto', $this->_customdata['returnto']);
$mform->setType('returnto', PARAM_URL);
}
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

View File

@ -224,7 +224,12 @@ class mod_lesson_renderer extends plugin_renderer_base {
while ($pageid != 0) {
$page = $lesson->load_page($pageid);
$data = array();
$data[] = "<a href=\"$CFG->wwwroot/mod/lesson/edit.php?id=".$this->page->cm->id."&amp;mode=single&amp;pageid=".$page->id."\">".format_string($page->title,true).'</a>';
$url = new moodle_url('/mod/lesson/edit.php', array(
'id' => $this->page->cm->id,
'mode' => 'single',
'pageid' => $page->id
));
$data[] = html_writer::link($url, format_string($page->title, true), array('id' => 'lesson-' . $page->id));
$data[] = $qtypes[$page->qtype];
$data[] = implode("<br />\n", $page->jumps);
if ($canedit) {
@ -274,6 +279,7 @@ class mod_lesson_renderer extends plugin_renderer_base {
$pagetable->cellspacing = 0;
$pagetable->cellpadding = '5px';
$pagetable->data = array();
$pagetable->id = 'lesson-' . $pageid;
$pageheading = new html_table_cell();