MDL-36757 course: avoid accidently overwriting the hidden/visible values set on grade...
authorAndrew Davis <andrew@moodle.com>
Wed, 19 Dec 2012 01:46:16 +0000 (09:46 +0800)
committerAndrew Davis <andrew@moodle.com>
Thu, 17 Jan 2013 03:37:09 +0000 (11:37 +0800)
course/lib.php

index 54dfc74..f4d8f48 100644 (file)
@@ -2874,6 +2874,13 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
     if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
         return false;
     }
+
+    // Create events and propagate visibility to associated grade items if the value has changed.
+    // Only do this if it's changed to avoid accidently overwriting manual showing/hiding of student grades.
+    if ($cm->visible == $visible) {
+        return true;
+    }
+
     if (!$modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module))) {
         return false;
     }
@@ -2887,7 +2894,7 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
         }
     }
 
-    // hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there
+    // Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there.
     $grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename, 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course));
     if ($grade_items) {
         foreach ($grade_items as $grade_item) {