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

This commit is contained in:
Ruslan Kabalin
2012-02-29 09:08:58 +00:00
parent 60e99097e4
commit 93d46f4802
4 changed files with 31 additions and 11 deletions
+1 -1
View File
@@ -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');
+22 -2
View File
@@ -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);
+1 -4
View File
@@ -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;
+7 -4
View File
@@ -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();
}
}
}