Permalink
Browse files

MDL-38703 course: moving a hidden course module unhides it

When moving to a non-hidden section because visibleold was not
being correctly set. visibleold should only be differnet from visible
when a CM is changed by section visibility
  • Loading branch information...
danpoltawski committed Mar 26, 2013
1 parent ba7c052 commit 470730c86b3f43b2462b3f18125e03ace15c3b37
Showing with 13 additions and 6 deletions.
  1. +13 −6 course/lib.php
View
@@ -2916,16 +2916,23 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
}
}
+ $cminfo = new stdClass();
+ $cminfo->id = $id;
+ $cminfo->visible = $visible;
+
if ($prevstateoverrides) {
- if ($visible == '0') {
- // Remember the current visible state so we can toggle this back.
- $DB->set_field('course_modules', 'visibleold', $cm->visible, array('id'=>$id));
+ // If we making whole section visiblility change..
+ if ($visible == 0) {
+ // Retain previous visibility state.
+ $cminfo->visibleold = $cm->visible;
} else {
- // Get the previous saved visible states.
- return $DB->set_field('course_modules', 'visible', $cm->visibleold, array('id'=>$id));
+ // Restore previous visibility state.
+ $cminfo->visible = $cm->visibleold;
}
+ } else {
+ $cminfo->visibleold = $visible;
}
- return $DB->set_field("course_modules", "visible", $visible, array("id"=>$id));
+ return $DB->update_record('course_modules', $cminfo);
}
/**

0 comments on commit 470730c

Please sign in to comment.