MDL-18301 Gradebook: Added feature for components to control grade visibility
authorFrederic Massart <fred@moodle.com>
Mon, 2 Jul 2012 04:49:57 +0000 (12:49 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 6 Jul 2012 01:53:54 +0000 (09:53 +0800)
grade/edit/tree/item.php
grade/edit/tree/item_form.php
lang/en/grades.php
lib/grade/grade_item.php
lib/moodlelib.php
mod/quiz/lib.php

index 5b2a7c0..0e80c6b 100644 (file)
@@ -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));
 
index 6dd9683..862a6fd 100644 (file)
@@ -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'));
index 5443b07..850e873 100644 (file)
@@ -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';
index 64913cb..8b1d312 100644 (file)
@@ -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;
+    }
 }
index 2dd1f58..92ca95e 100644 (file)
@@ -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');
index 97bd198..6e28cbf 100644 (file)
@@ -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;
     }