MDL-43068 course&gradebook: show/hide cm & CONTROLS_GRADE_VISIBILITY

Making a quiz visible on the course page, of via the settings form,
could cause the grade item to become visible in the gradebook, even
though the quiz supports FEATURE_CONTROLS_GRADE_VISIBILITY to ensure
that when the grades are hidden in the quiz settings, they do not appear
in the gradebook.

Now, if a module supports FEATURE_CONTROLS_GRADE_VISIBILITY, then
set_coursemodule_visible calls the _grade_item_update callback to update
the grade item(s).

In addition, there was a bug when saving the quiz form, where it used
the value of $cm->visible from the database, which was wrong if the
value of cm->visible had just been changed on the setting form.
This commit is contained in:
Tim Hunt 2013-11-27 17:40:40 +00:00
parent f7434db109
commit 1c73df9eea
2 changed files with 23 additions and 10 deletions

View File

@ -1595,14 +1595,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();
@ -1611,6 +1603,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 File

@ -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') {