Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-33367 course: move_section reuse move_section_to function

Conflicts:

	course/lib.php
  • Loading branch information...
commit eb01aa2c340124c2a65408c50ae3f908d05394d3 1 parent 4db0616
Rajesh Taneja rajeshtaneja authored
43 course/lib.php
@@ -2963,41 +2963,12 @@ function move_section($course, $section, $move) {
2963 2963 return false;
2964 2964 }
2965 2965
2966   - if (!$sectionrecord = $DB->get_record("course_sections", array("course"=>$course->id, "section"=>$section))) {
2967   - return false;
2968   - }
2969   -
2970   - if (!$sectiondestrecord = $DB->get_record("course_sections", array("course"=>$course->id, "section"=>$sectiondest))) {
2971   - return false;
2972   - }
2973   -
2974   - // Three-step change ensures that the section always remains unique (there is
2975   - // a unique index now)
2976   - $DB->set_field("course_sections", "section", -$sectiondest, array("id"=>$sectionrecord->id));
2977   - $DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id));
2978   - $DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id));
2979   -
2980   - // Update highlighting if the move affects highlighted section
2981   - if ($course->marker == $section) {
2982   - course_set_marker($course->id, $sectiondest);
2983   - } elseif ($course->marker == $sectiondest) {
2984   - course_set_marker($course->id, $section);
  2966 + $retval = move_section_to($course, $section, $sectiondest);
  2967 + // If section moved, then rebuild course cache.
  2968 + if ($retval) {
  2969 + rebuild_course_cache($course->id, true);
2985 2970 }
2986   -
2987   -
2988   - // Fix order if needed. The database prevents duplicate sections, but it is
2989   - // possible there could be a gap in the numbering.
2990   - $sections = $DB->get_records('course_sections', array('course'=>$course->id), 'section ASC');
2991   - $n = 0;
2992   - foreach ($sections as $section) {
2993   - if ($section->section != $n) {
2994   - $DB->set_field('course_sections', 'section', $n, array('id'=>$section->id));
2995   - }
2996   - $n++;
2997   - }
2998   - // After moving section, rebuild course cache.
2999   - rebuild_course_cache($course->id, true);
3000   - return true;
  2971 + return $retval;
3001 2972 }
3002 2973
3003 2974 /**
@@ -3107,6 +3078,10 @@ function reorder_sections($sections, $origin_position, $target_position) {
3107 3078 unset($sections[$id]);
3108 3079 }
3109 3080 if ($position == $target_position) {
  3081 + if ($target_position < $origin_position) {
  3082 + $append_array[$id] = $position;
  3083 + unset($sections[$id]);
  3084 + }
3110 3085 $found = true;
3111 3086 }
3112 3087 }
10 course/tests/courselib_test.php
@@ -52,6 +52,16 @@ public function test_reorder_sections() {
52 52 $this->assertEquals($oldsections[5], $neworder[5]);
53 53 $this->assertEquals($oldsections[6], $neworder[6]);
54 54
  55 + $neworder = reorder_sections($sections, 4, 2);
  56 + $neworder = array_keys($neworder);
  57 + $this->assertEquals($oldsections[0], $neworder[0]);
  58 + $this->assertEquals($oldsections[1], $neworder[1]);
  59 + $this->assertEquals($oldsections[2], $neworder[3]);
  60 + $this->assertEquals($oldsections[3], $neworder[4]);
  61 + $this->assertEquals($oldsections[4], $neworder[2]);
  62 + $this->assertEquals($oldsections[5], $neworder[5]);
  63 + $this->assertEquals($oldsections[6], $neworder[6]);
  64 +
55 65 $neworder = reorder_sections(1, 2, 4);
56 66 $this->assertFalse($neworder);
57 67 }
4 course/yui/dragdrop/dragdrop.js
@@ -135,12 +135,10 @@ YUI.add('moodle-course-dragdrop', function(Y) {
135 135 var dragnodeid = Number(this.get_section_id(dragnode));
136 136 var dropnodeid = Number(this.get_section_id(dropnode));
137 137
138   - var targetoffset = 0;
139 138 var loopstart = dragnodeid;
140 139 var loopend = dropnodeid;
141 140
142 141 if (this.goingup) {
143   - targetoffset = 1;
144 142 loopstart = dropnodeid;
145 143 loopend = dragnodeid;
146 144 }
@@ -166,7 +164,7 @@ YUI.add('moodle-course-dragdrop', function(Y) {
166 164 params['class'] = 'section';
167 165 params.field = 'move';
168 166 params.id = dragnodeid;
169   - params.value = dropnodeid - targetoffset;
  167 + params.value = dropnodeid;
170 168
171 169 // Do AJAX request
172 170 var uri = M.cfg.wwwroot + this.get('ajaxurl');

0 comments on commit eb01aa2

Please sign in to comment.
Something went wrong with that request. Please try again.