From 0f07802493cfdfd14b62c2c1a5038f828849daff Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 16 Sep 2010 08:16:26 +0000 Subject: [PATCH] MDL-15457 gradebook: fixing a regression, plain fetch() does not work with modules having multiple grade items per instance such as workshop --- course/lib.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/course/lib.php b/course/lib.php index 6a64c855ab1..8e95cc48b10 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2577,6 +2577,8 @@ function set_coursemodule_idnumber($id, $idnumber) { */ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) { global $DB, $CFG; + require_once($CFG->libdir.'/gradelib.php'); + if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) { return false; } @@ -2593,11 +2595,12 @@ function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) { } } - //hide the grade item so the teacher doesn't also have to go to the gradebook and hide it there - require_once($CFG->libdir.'/gradelib.php'); - $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$modulename, 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course)); - if ($grade_item !== false) { - $grade_item->set_hidden(!$visible); + // 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) { + $grade_item->set_hidden(!$visible); + } } if ($prevstateoverrides) {