Merge branch 'MDL-33775-master-integration' of git://github.com/FMCorz/moodle

This commit is contained in:
Dan Poltawski 2012-06-18 15:18:02 +08:00
commit e73c1cafa1
6 changed files with 28 additions and 13 deletions

View file

@ -539,7 +539,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
echo $this->section_header($thissection, $course, true); echo $this->section_header($thissection, $course, true);
print_section($course, $thissection, $mods, $modnamesused, true); print_section($course, $thissection, $mods, $modnamesused, true);
if ($PAGE->user_is_editing()) { 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->section_footer();
echo $this->end_section_list(); 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); print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, true);
if ($PAGE->user_is_editing()) { 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->section_footer();
echo $this->end_section_list(); echo $this->end_section_list();

View file

@ -1762,7 +1762,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
/** /**
* Prints the menus to add activities and resources. * 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; global $CFG, $OUTPUT;
// check to see if user can add menus // 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 // We need to add the section section to the link for each module
$sectionlink = '&section=' . $section; $sectionlink = '&section=' . $section;
// We need to add the section to return to
if ($sectionreturn) {
$sectionreturnlink = '&sr=' . $section;
} else {
$sectionreturnlink = '&sr=0';
}
foreach ($modules as $module) { foreach ($modules as $module) {
if (isset($module->types)) { if (isset($module->types)) {
// This module has a subtype // This module has a subtype
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!! // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
$subtypes = array(); $subtypes = array();
foreach ($module->types as $subtype) { foreach ($module->types as $subtype) {
$subtypes[$subtype->link . $sectionlink] = $subtype->title; $subtypes[$subtype->link . $sectionlink . $sectionreturnlink] = $subtype->title;
} }
// Sort module subtypes into the list // Sort module subtypes into the list
@ -1808,11 +1815,11 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
} else { } else {
// This module has no subtypes // This module has no subtypes
if ($module->archetype == MOD_ARCHETYPE_RESOURCE) { 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) { } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
// System modules cannot be added by user, do not add to dropdown // System modules cannot be added by user, do not add to dropdown
} else { } 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 object $course The Course
* @param array $modnames An array containing the list of modules and their * @param array $modnames An array containing the list of modules and their
* names * names
* @param int $sectionreturn The section to return to
* @return array A list of stdClass objects containing metadata about each * @return array A list of stdClass objects containing metadata about each
* module * module
*/ */
function get_module_metadata($course, $modnames) { function get_module_metadata($course, $modnames, $sectionreturn = 0) {
global $CFG, $OUTPUT; global $CFG, $OUTPUT;
// get_module_metadata will be called once per section on the page and courses may show // 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(); $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) { foreach($modnames as $modname => $modnamestr) {
if (!course_allowed_module($course, $modname)) { if (!course_allowed_module($course, $modname)) {
continue; continue;

View file

@ -73,12 +73,12 @@ if (!empty($add)) {
$type = optional_param('type', '', PARAM_ALPHA); $type = optional_param('type', '', PARAM_ALPHA);
$returntomod = optional_param('return', 0, PARAM_BOOL); $returntomod = optional_param('return', 0, PARAM_BOOL);
redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id&section=$section&return=$returntomod"); redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id&section=$section&return=$returntomod&sr=$sectionreturn");
} else if (!empty($update)) { } else if (!empty($update)) {
$cm = get_coursemodule_from_id('', $update, 0, true, MUST_EXIST); $cm = get_coursemodule_from_id('', $update, 0, true, MUST_EXIST);
$returntomod = optional_param('return', 0, PARAM_BOOL); $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)) { } else if (!empty($duplicate)) {
$cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST); $cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST);

View file

@ -35,8 +35,10 @@ $add = optional_param('add', '', PARAM_ALPHA); // module name
$update = optional_param('update', 0, PARAM_INT); $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 $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 $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 = new moodle_url('/course/modedit.php');
$url->param('sr', $sectionreturn);
if (!empty($return)) { if (!empty($return)) {
$url->param('return', $return); $url->param('return', $return);
} }
@ -79,6 +81,7 @@ if (!empty($add)) {
$data->coursemodule = ''; $data->coursemodule = '';
$data->add = $add; $data->add = $add;
$data->return = 0; //must be false if this is an add, go back to course view on cancel $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)) { if (plugin_supports('mod', $data->modulename, FEATURE_MOD_INTRO, true)) {
$draftid_editor = file_get_submitted_draft_itemid('introeditor'); $draftid_editor = file_get_submitted_draft_itemid('introeditor');
@ -147,6 +150,7 @@ if (!empty($add)) {
$data->modulename = $module->name; $data->modulename = $module->name;
$data->instance = $cm->instance; $data->instance = $cm->instance;
$data->return = $return; $data->return = $return;
$data->sr = $sectionreturn;
$data->update = $update; $data->update = $update;
$data->completion = $cm->completion; $data->completion = $cm->completion;
$data->completionview = $cm->completionview; $data->completionview = $cm->completionview;
@ -260,7 +264,7 @@ if ($mform->is_cancelled()) {
if ($return && !empty($cm->id)) { if ($return && !empty($cm->id)) {
redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id");
} else { } else {
redirect(course_get_url($course, $cw->section)); redirect(course_get_url($course, $sectionreturn));
} }
} else if ($fromform = $mform->get_data()) { } else if ($fromform = $mform->get_data()) {
if (empty($fromform->coursemodule)) { if (empty($fromform->coursemodule)) {
@ -629,7 +633,7 @@ if ($mform->is_cancelled()) {
redirect($gradingman->get_management_url($returnurl)); redirect($gradingman->get_management_url($returnurl));
} }
} else { } else {
redirect(course_get_url($course, $cw->section)); redirect(course_get_url($course, $sectionreturn));
} }
exit; exit;

View file

@ -690,6 +690,9 @@ abstract class moodleform_mod extends moodleform {
$mform->addElement('hidden', 'return', 0); $mform->addElement('hidden', 'return', 0);
$mform->setType('return', PARAM_BOOL); $mform->setType('return', PARAM_BOOL);
$mform->addElement('hidden', 'sr', 0);
$mform->setType('sr', PARAM_INT);
} }
public function standard_grading_coursemodule_elements() { public function standard_grading_coursemodule_elements() {

View file

@ -270,7 +270,7 @@
if (include_course_ajax($course, $modnamesused)) { if (include_course_ajax($course, $modnamesused)) {
// Add the module chooser // Add the module chooser
$renderer = $PAGE->get_renderer('core', 'course'); $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(); echo $OUTPUT->footer();