diff --git a/course/lib.php b/course/lib.php index c3e520f..cc1a787 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2247,12 +2247,20 @@ function move_section($course, $section, $move) { return false; } - if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { - return false; + + $count = abs($sectiondest - $section); + $direction = ($sectiondest - $section) / $count; + + for ($i = 0, $ref = $section + $direction; $i < $count; ++$i, $ref += $direction) { + if (!set_field("course_sections", "section", $ref - $direction, 'course', $course->id, 'section', $ref)) { + return false; + } } - if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) { + + if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { return false; } + // if the focus is on the section that is being moved, then move the focus along if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) { course_set_display($course->id, $sectiondest);