mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-33775 Course: fix redirect to course/section in paged mode
This commit is contained in:
parent
728aee9767
commit
a41b1d96b6
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user