Permalink
Browse files

MDL-31255 Fix move of highlighted section when JS is off

Conflicts:

	course/rest.php
	course/view.php
  • Loading branch information...
1 parent ce0e7af commit e57b1ed36cb39194d258fb76b9e4b6aaf3de3351 Ruslan Kabalin committed with stronk7 Jan 19, 2012
Showing with 31 additions and 11 deletions.
  1. +1 −1 course/format/topics/format.php
  2. +22 −2 course/lib.php
  3. +1 −4 course/rest.php
  4. +7 −4 course/view.php
@@ -42,7 +42,7 @@
if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
$course->marker = $marker;
- $DB->set_field("course", "marker", $marker, array("id"=>$course->id));
+ course_set_marker($course->id, $marker);
}
$streditsummary = get_string('editsummary');
View
@@ -1334,6 +1334,18 @@ function course_set_display($courseid, $display) {
}
/**
+ * Set highlighted section. Only one section can be highlighted at the time.
+ *
+ * @param int $courseid course id
+ * @param int $marker highlight section with this number, 0 means remove higlightin
+ * @return void
+ */
+function course_set_marker($courseid, $marker) {
+ global $DB;
+ $DB->set_field("course", "marker", $marker, array('id' => $courseid));
+}
+
+/**
* For a given course section, marks it visible or hidden,
* and does the same for every activity in that section
*/
@@ -2850,9 +2862,10 @@ function delete_mod_from_section($mod, $section) {
/**
* Moves a section up or down by 1. CANNOT BE USED DIRECTLY BY AJAX!
*
- * @param object $course
- * @param int $section
+ * @param object $course course object
+ * @param int $section Section number (not id!!!)
* @param int $move (-1 or 1)
+ * @return boolean true if section moved successfully
*/
function move_section($course, $section, $move) {
/// Moves a whole course section up and down within the course
@@ -2879,6 +2892,13 @@ function move_section($course, $section, $move) {
$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id));
$DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id));
+ // Update highlighting if the move affects highlighted section
+ if ($course->marker == $section) {
+ course_set_marker($course->id, $sectiondest);
+ } elseif ($course->marker == $sectiondest) {
+ course_set_marker($course->id, $section);
+ }
+
// if the focus is on the section that is being moved, then move the focus along
if (course_get_display($course->id) == $section) {
course_set_display($course->id, $sectiondest);
View
@@ -158,10 +158,7 @@
case 'course':
switch($field) {
case 'marker':
- $newcourse = new stdClass();
- $newcourse->id = $course->id;
- $newcourse->marker = $value;
- $DB->update_record('course', $newcourse);
+ course_set_marker($course->id, $value);
break;
}
break;
View
@@ -137,12 +137,15 @@
if (!empty($section)) {
if (!empty($move) and confirm_sesskey()) {
- if (!move_section($course, $section, $move)) {
+ if (move_section($course, $section, $move)) {
+ if ($course->id == SITEID) {
+ redirect($CFG->wwwroot . '/?redirect=0');
+ } else {
+ redirect($PAGE->url);
+ }
+ } else {
echo $OUTPUT->notification('An error occurred while moving a section');
}
- // Clear the navigation cache at this point so that the affects
- // are seen immediately on the navigation.
- $PAGE->navigation->clear_cache();
}
}
} else {

0 comments on commit e57b1ed

Please sign in to comment.