From d33a2a6f39c4ee9ce1886b2d4445424b750d745f Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sun, 30 May 2004 23:09:21 +0000 Subject: [PATCH] It is now possible to duplicate a course module. See http://moodle.org/mod/forum/discuss.php?d=8468 --- course/lib.php | 2 ++ course/mod.php | 97 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/course/lib.php b/course/lib.php index ebe8868c39..de9c8eaee5 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1527,6 +1527,7 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=- $str->moveright = get_string("moveright"); $str->moveleft = get_string("moveleft"); $str->update = get_string("update"); + $str->duplicate = get_string("duplicate"); $str->hide = get_string("hide"); $str->show = get_string("show"); $str->clicktochange = get_string("clicktochange"); @@ -1603,6 +1604,7 @@ function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=- return "$leftright$move". "update\" href=\"$path/mod.php?update=$mod->id\">". + "duplicate\" href=\"$path/mod.php?duplicate=$mod->id\"> 2 ". "delete\" href=\"$path/mod.php?delete=$mod->id\">$hideshow$groupmode"; } diff --git a/course/mod.php b/course/mod.php index 67bcbd129f..f161f0517f 100644 --- a/course/mod.php +++ b/course/mod.php @@ -1,6 +1,6 @@ instance", $mod->coursemodule); break; + case "add": + $return = $addinstancefunction($mod); + if (!$return) { + if (file_exists($moderr)) { + $form = $mod; + include_once($moderr); + die; + } + error("Could not add a new instance of $mod->modulename", "view.php?id=$course->id"); + } + if (is_string($return)) { + error($return, "view.php?id=$course->id"); + } + + $mod->groupmode = $course->groupmode; /// Default groupmode the same as course + + $mod->instance = $return; + // course_modules and course_sections each contain a reference + // to each other, so we have to update one of them twice. + + if (! $mod->coursemodule = add_course_module($mod) ) { + error("Could not add a new course module"); + } + if (! $sectionid = add_mod_to_section($mod) ) { + error("Could not add the new course module to that section"); + } + //We get the section's visible field status + $visible = get_field("course_sections","visible","id",$sectionid); + + if (! set_field("course_modules", "visible", $visible, "id", $mod->coursemodule)) { + error("Could not update the course module with the correct visibility"); + } + + if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { + error("Could not update the course module with the correct section"); + } + add_to_log($course->id, "course", "add mod", + "../mod/$mod->modulename/view.php?id=$mod->coursemodule", + "$mod->modulename $mod->instance"); + add_to_log($course->id, $mod->modulename, "add", + "view.php?id=$mod->coursemodule", + "$mod->instance", $mod->coursemodule); + break; + case "add": $return = $addinstancefunction($mod); if (!$return) { @@ -456,6 +500,57 @@ $pageheading = get_string("updatinga", "moodle", $fullmodulename); } + } else if (isset($_GET['duplicate'])) { // value = course module + + if (! $cm = get_record("course_modules", "id", $_GET['duplicate'])) { + error("This course module doesn't exist"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("This course doesn't exist"); + } + + if (!isteacheredit($course->id)) { + error("You can't modify this course!"); + } + + if (! $module = get_record("modules", "id", $cm->module)) { + error("This module doesn't exist"); + } + + if (! $form = get_record($module->name, "id", $cm->instance)) { + error("The required instance of this module doesn't exist"); + } + + if (! $cw = get_record("course_sections", "id", $cm->section)) { + error("This course section doesn't exist"); + } + + if (isset($return)) { + $SESSION->returnpage = "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"; + } + + $section = get_field('course_sections', 'section', 'id', $cm->section); + + $form->coursemodule = $cm->id; + $form->section = $section; // The section ID + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->instance = $cm->instance; + $form->mode = "add"; + + $sectionname = get_string("name$course->format"); + $fullmodulename = strtolower(get_string("modulename", $module->name)); + + if ($form->section) { + $heading->what = $fullmodulename; + $heading->in = "$sectionname $cw->section"; + $pageheading = get_string("duplicatingain", "moodle", $heading); + } else { + $pageheading = get_string("duplicatinga", "moodle", $fullmodulename); + } + } else if (isset($_GET['add'])) { -- 2.39.5