From: moodler Date: Tue, 10 Jun 2003 15:27:09 +0000 (+0000) Subject: Sections can now be moved up and down X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=12905134abacadc9b23a89f87ec99a83d25058fd;p=moodle.git Sections can now be moved up and down --- diff --git a/course/lib.php b/course/lib.php index 4a2e2d4940..131282982c 100644 --- a/course/lib.php +++ b/course/lib.php @@ -929,7 +929,6 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) { /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// function add_course_module($mod) { - GLOBAL $db; $mod->added = time(); @@ -974,7 +973,6 @@ function delete_course_module($mod) { } function delete_mod_from_section($mod, $section) { - GLOBAL $db; if ($section = get_record("course_sections", "id", "$section") ) { @@ -993,9 +991,43 @@ function delete_mod_from_section($mod, $section) { } } +function move_section($course, $section, $move) { +/// Moves a whole course section up and down within the course + + if (!$move) { + return true; + } + + $sectiondest = $section + $move; + + if ($sectiondest > $course->numsections or $sectiondest < 1) { + return false; + } + + if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) { + return false; + } + + if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) { + return false; + } + + $sectionrecord->section = $sectiondest; + $sectiondestrecord->section = $section; + + if (!update_record("course_sections", $sectionrecord)) { + return false; + } + if (!update_record("course_sections", $sectiondestrecord)) { + return false; + } + return true; +} + + function move_module($cm, $move) { - GLOBAL $db; +/// Moves an activity module up and down within the course if (!$move) { return true; diff --git a/course/topics.php b/course/topics.php index fb739a163c..a9c9994cb4 100644 --- a/course/topics.php +++ b/course/topics.php @@ -223,6 +223,16 @@ "
"; } + if ($section > 1) { // Add a arrow to move section up + echo "id§ion=$section&move=-1\" title=\"$strtopicup\">". + "
"; + } + + if ($section < $course->numsections) { // Add a arrow to move section down + echo "id§ion=$section&move=1\" title=\"$strtopicdown\">". + "
"; + } + } echo ""; diff --git a/course/view.php b/course/view.php index 35a0c34216..c4b78f6fa9 100644 --- a/course/view.php +++ b/course/view.php @@ -42,6 +42,12 @@ if (isset($show)) { set_section_visible($course->id, $show, "1"); } + + if (!empty($section)) { + if (!empty($move)) { + move_section($course, $section, $move); + } + } } $SESSION->fromdiscussion = "$CFG->wwwroot/course/view.php?id=$course->id"; diff --git a/course/weeks.php b/course/weeks.php index daabd6c80f..ba60deb6e5 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -215,6 +215,17 @@ echo "id&show=$section\" title=\"$strweekshow\">". "
"; } + + if ($section > 1) { // Add a arrow to move section up + echo "id§ion=$section&move=-1\" title=\"$strtopicup\">". + "
"; + } + + if ($section < $course->numsections) { // Add a arrow to move section down + echo "id§ion=$section&move=1\" title=\"$strtopicdown\">". + "
"; + } + } echo "";