Permalink
Browse files

Merge branch 'MDL-43068_24' of git://github.com/timhunt/moodle into M…

…OODLE_24_STABLE
  • Loading branch information...
2 parents 7842d36 + 5536723 commit d8d43cdc183184d741f3f51c7badfbc6ed9d0365 @danpoltawski danpoltawski committed Dec 2, 2013
Showing with 23 additions and 10 deletions.
  1. +16 −8 course/lib.php
  2. +7 −2 mod/quiz/lib.php
View
@@ -2917,14 +2917,6 @@ function set_coursemodule_visible($id, $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);
- }
- }
-
// Updating visible and visibleold to keep them in sync. Only changing a section visibility will
// affect visibleold to allow for an original visibility restore. See set_section_visible().
$cminfo = new stdClass();
@@ -2933,6 +2925,22 @@ function set_coursemodule_visible($id, $visible) {
$cminfo->visibleold = $visible;
$DB->update_record('course_modules', $cminfo);
+ // Hide the associated grade items so the teacher doesn't also have to go to the gradebook and hide them there.
+ // Note that this must be done after updating the row in course_modules, in case
+ // the modules grade_item_update function needs to access $cm->visible.
+ if (plugin_supports('mod', $modulename, FEATURE_CONTROLS_GRADE_VISIBILITY) &&
+ component_callback_exists('mod_' . $modulename, 'grade_item_update')) {
+ $instance = $DB->get_record($modulename, array('id' => $cm->instance), '*', MUST_EXIST);
+ component_callback('mod_' . $modulename, 'grade_item_update', array($instance));
+ } else {
+ $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);
+ }
+ }
+ }
+
rebuild_course_cache($cm->course, true);
return true;
}
View
@@ -722,8 +722,13 @@ function quiz_grade_item_update($quiz, $grades = null) {
if (!$params['hidden']) {
// If the grade item is not hidden by the quiz logic, then we need to
// hide it if the quiz is hidden from students.
- $cm = get_coursemodule_from_instance('quiz', $quiz->id);
- $params['hidden'] = !$cm->visible;
+ if (property_exists($quiz, 'visible')) {
+ // Saving the quiz form, and cm not yet updated in the database.
+ $params['hidden'] = !$quiz->visible;
+ } else {
+ $cm = get_coursemodule_from_instance('quiz', $quiz->id);
+ $params['hidden'] = !$cm->visible;
+ }
}
if ($grades === 'reset') {

0 comments on commit d8d43cd

Please sign in to comment.