From 2dd2bd7ead4d1cb47cd59b6ee3299df71146e3a4 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 2 Jul 2012 12:49:57 +0800 Subject: [PATCH] MDL-18301 Gradebook: Added feature for components to control grade visibility --- grade/edit/tree/item.php | 1 + grade/edit/tree/item_form.php | 15 +++++++++++---- lang/en/grades.php | 1 + lib/grade/grade_item.php | 12 ++++++++++++ lib/moodlelib.php | 2 ++ mod/quiz/lib.php | 19 ++++++++++--------- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index 5b2a7c0a9c9..0e80c6befce 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -97,6 +97,7 @@ if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->ag } else { $item->aggregationcoef = format_float($item->aggregationcoef, 4); } +$item->cancontrolvisibility = $grade_item->can_control_visibility(); $mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr)); diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index 6dd9683b2e2..862a6fd6530 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -143,11 +143,18 @@ class edit_item_form extends moodleform { } /// hiding - // advcheckbox is not compatible with disabledIf! - $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); + if ($item->cancontrolvisibility) { + // advcheckbox is not compatible with disabledIf! + $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); + $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true)); + $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); + } else { + $mform->addElement('static', 'hidden', get_string('hidden', 'grades'), + get_string('componentcontrolsvisibility', 'grades')); + // Unset hidden to avoid data override. + unset($item->hidden); + } $mform->addHelpButton('hidden', 'hidden', 'grades'); - $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true)); - $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); /// locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); diff --git a/lang/en/grades.php b/lang/en/grades.php index 5443b079226..850e8737d0d 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -117,6 +117,7 @@ $string['categorytotalname'] = 'Category total name'; $string['categorytotalfull'] = '{$a->category} total'; $string['combo'] = 'Tabs and Dropdown menu'; $string['compact'] = 'Compact'; +$string['componentcontrolsvisibility'] = 'Whether this grade item is hidden is controlled by the activity settings.'; $string['contract'] = 'Contract category'; $string['controls'] = 'Controls'; $string['courseavg'] = 'Course average'; diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 64913cbd9e3..8b1d3122f08 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -2067,4 +2067,16 @@ class grade_item extends grade_object { return false; } } + + /** + * Returns whether the grade item can control the visibility of the grades + * + * @return bool + */ + public function can_control_visibility() { + if (get_plugin_directory($this->itemtype, $this->itemmodule)) { + return !plugin_supports($this->itemtype, $this->itemmodule, FEATURE_CONTROLS_GRADE_VISIBILITY, false); + } + return true; + } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 2dd1f58addf..92ca95eb05b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -385,6 +385,8 @@ define('FEATURE_GRADE_HAS_GRADE', 'grade_has_grade'); define('FEATURE_GRADE_OUTCOMES', 'outcomes'); /** True if module supports advanced grading methods */ define('FEATURE_ADVANCED_GRADING', 'grade_advanced_grading'); +/** True if module controls the grade visibility over the gradebook */ +define('FEATURE_CONTROLS_GRADE_VISIBILITY', 'controlsgradevisbility'); /** True if module has code to track whether somebody viewed it */ define('FEATURE_COMPLETION_TRACKS_VIEWS', 'completion_tracks_views'); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 97bd198fa05..6e28cbfec20 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1550,15 +1550,16 @@ function quiz_attempt_summary_link_to_reports($quiz, $cm, $context, $returnzero */ function quiz_supports($feature) { switch($feature) { - case FEATURE_GROUPS: return true; - case FEATURE_GROUPINGS: return true; - case FEATURE_GROUPMEMBERSONLY: return true; - case FEATURE_MOD_INTRO: return true; - case FEATURE_COMPLETION_TRACKS_VIEWS: return true; - case FEATURE_GRADE_HAS_GRADE: return true; - case FEATURE_GRADE_OUTCOMES: return false; - case FEATURE_BACKUP_MOODLE2: return true; - case FEATURE_SHOW_DESCRIPTION: return true; + case FEATURE_GROUPS: return true; + case FEATURE_GROUPINGS: return true; + case FEATURE_GROUPMEMBERSONLY: return true; + case FEATURE_MOD_INTRO: return true; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_GRADE_HAS_GRADE: return true; + case FEATURE_GRADE_OUTCOMES: return false; + case FEATURE_BACKUP_MOODLE2: return true; + case FEATURE_SHOW_DESCRIPTION: return true; + case FEATURE_CONTROLS_GRADE_VISIBILITY: return true; default: return null; }