From 93d46f48020ea96edb7ddf77dfa9b9edb039e382 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Thu, 19 Jan 2012 11:35:46 +0000 Subject: [PATCH] MDL-31255 Fix move of highlighted section when JS is off --- course/format/topics/format.php | 2 +- course/lib.php | 24 ++++++++++++++++++++++-- course/rest.php | 5 +---- course/view.php | 11 +++++++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 7e2430540ca..42b07d99301 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -42,7 +42,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id); 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'); diff --git a/course/lib.php b/course/lib.php index c1864229d64..b51405cc901 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1334,6 +1334,18 @@ function course_set_display($courseid, $display) { return $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 @@ -2862,9 +2874,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 @@ -2891,6 +2904,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); diff --git a/course/rest.php b/course/rest.php index 933e4f1a9c1..5125ffb72d3 100644 --- a/course/rest.php +++ b/course/rest.php @@ -159,10 +159,7 @@ switch($requestmethod) { require_login($course); $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:update', $coursecontext); - $newcourse = new stdClass(); - $newcourse->id = $course->id; - $newcourse->marker = $value; - $DB->update_record('course', $newcourse); + course_set_marker($course->id, $value); break; } break; diff --git a/course/view.php b/course/view.php index 7317094058f..8b2621f38a0 100644 --- a/course/view.php +++ b/course/view.php @@ -138,12 +138,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(); } } }