From a41b1d96b66b015a8d6dcde4342b6e502396beed Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 15 Jun 2012 16:16:52 +0800 Subject: [PATCH] MDL-33775 Course: fix redirect to course/section in paged mode --- course/format/renderer.php | 4 ++-- course/lib.php | 20 ++++++++++++++------ course/mod.php | 4 ++-- course/modedit.php | 8 ++++++-- course/moodleform_mod.php | 3 +++ course/view.php | 2 +- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/course/format/renderer.php b/course/format/renderer.php index f0655a9bb84..8de249c6286 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -539,7 +539,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { echo $this->section_header($thissection, $course, true); print_section($course, $thissection, $mods, $modnamesused, true); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, $modnames); + print_section_add_menus($course, 0, $modnames, false, false, true); } echo $this->section_footer(); echo $this->end_section_list(); @@ -575,7 +575,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, true); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $displaysection, $modnames); + print_section_add_menus($course, $displaysection, $modnames, false, false, true); } echo $this->section_footer(); echo $this->end_section_list(); diff --git a/course/lib.php b/course/lib.php index 26fea7250e0..75bba78ad15 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1762,7 +1762,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, /** * Prints the menus to add activities and resources. */ -function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) { +function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false, $sectionreturn = false) { global $CFG, $OUTPUT; // check to see if user can add menus @@ -1780,13 +1780,20 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, // We need to add the section section to the link for each module $sectionlink = '§ion=' . $section; + // We need to add the section to return to + if ($sectionreturn) { + $sectionreturnlink = '&sr=' . $section; + } else { + $sectionreturnlink = '&sr=0'; + } + foreach ($modules as $module) { if (isset($module->types)) { // This module has a subtype // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!! $subtypes = array(); foreach ($module->types as $subtype) { - $subtypes[$subtype->link . $sectionlink] = $subtype->title; + $subtypes[$subtype->link . $sectionlink . $sectionreturnlink] = $subtype->title; } // Sort module subtypes into the list @@ -1808,11 +1815,11 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, } else { // This module has no subtypes if ($module->archetype == MOD_ARCHETYPE_RESOURCE) { - $resources[$module->link . $sectionlink] = $module->title; + $resources[$module->link . $sectionlink . $sectionreturnlink] = $module->title; } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) { // System modules cannot be added by user, do not add to dropdown } else { - $activities[$module->link . $sectionlink] = $module->title; + $activities[$module->link . $sectionlink . $sectionreturnlink] = $module->title; } } } @@ -1880,10 +1887,11 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, * @param object $course The Course * @param array $modnames An array containing the list of modules and their * names + * @param int $sectionreturn The section to return to * @return array A list of stdClass objects containing metadata about each * module */ -function get_module_metadata($course, $modnames) { +function get_module_metadata($course, $modnames, $sectionreturn = 0) { global $CFG, $OUTPUT; // get_module_metadata will be called once per section on the page and courses may show @@ -1894,7 +1902,7 @@ function get_module_metadata($course, $modnames) { } $return = array(); - $urlbase = "/course/mod.php?id=$course->id&sesskey=".sesskey().'&add='; + $urlbase = "/course/mod.php?id=$course->id&sesskey=".sesskey().'&sr='.$sectionreturn.'&add='; foreach($modnames as $modname => $modnamestr) { if (!course_allowed_module($course, $modname)) { continue; diff --git a/course/mod.php b/course/mod.php index 0dcfe1091cb..181c6c9d21a 100644 --- a/course/mod.php +++ b/course/mod.php @@ -73,12 +73,12 @@ if (!empty($add)) { $type = optional_param('type', '', PARAM_ALPHA); $returntomod = optional_param('return', 0, PARAM_BOOL); - redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod"); + redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod&sr=$sectionreturn"); } else if (!empty($update)) { $cm = get_coursemodule_from_id('', $update, 0, true, MUST_EXIST); $returntomod = optional_param('return', 0, PARAM_BOOL); - redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod"); + redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod&sr=$sectionreturn"); } else if (!empty($duplicate)) { $cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST); diff --git a/course/modedit.php b/course/modedit.php index b9bf127826d..ff9861382d6 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -35,8 +35,10 @@ $add = optional_param('add', '', PARAM_ALPHA); // module name $update = optional_param('update', 0, PARAM_INT); $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true $type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0 +$sectionreturn = optional_param('sr', 0, PARAM_INT); $url = new moodle_url('/course/modedit.php'); +$url->param('sr', $sectionreturn); if (!empty($return)) { $url->param('return', $return); } @@ -79,6 +81,7 @@ if (!empty($add)) { $data->coursemodule = ''; $data->add = $add; $data->return = 0; //must be false if this is an add, go back to course view on cancel + $data->sr = $sectionreturn; if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) { $draftid_editor = file_get_submitted_draft_itemid('introeditor'); @@ -147,6 +150,7 @@ if (!empty($add)) { $data->modulename = $module->name; $data->instance = $cm->instance; $data->return = $return; + $data->sr = $sectionreturn; $data->update = $update; $data->completion = $cm->completion; $data->completionview = $cm->completionview; @@ -260,7 +264,7 @@ if ($mform->is_cancelled()) { if ($return && !empty($cm->id)) { redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); } else { - redirect(course_get_url($course, $cw->section)); + redirect(course_get_url($course, $sectionreturn)); } } else if ($fromform = $mform->get_data()) { if (empty($fromform->coursemodule)) { @@ -629,7 +633,7 @@ if ($mform->is_cancelled()) { redirect($gradingman->get_management_url($returnurl)); } } else { - redirect(course_get_url($course, $cw->section)); + redirect(course_get_url($course, $sectionreturn)); } exit; diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index a9a3b53ecb7..292387b9dbd 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -690,6 +690,9 @@ abstract class moodleform_mod extends moodleform { $mform->addElement('hidden', 'return', 0); $mform->setType('return', PARAM_BOOL); + + $mform->addElement('hidden', 'sr', 0); + $mform->setType('sr', PARAM_INT); } public function standard_grading_coursemodule_elements() { diff --git a/course/view.php b/course/view.php index e0f295b466e..e4a18cda2d3 100644 --- a/course/view.php +++ b/course/view.php @@ -270,7 +270,7 @@ if (include_course_ajax($course, $modnamesused)) { // Add the module chooser $renderer = $PAGE->get_renderer('core', 'course'); - echo $renderer->course_modchooser(get_module_metadata($course, $modnames), $course); + echo $renderer->course_modchooser(get_module_metadata($course, $modnames, $displaysection), $course); } echo $OUTPUT->footer();