diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php
index 0ceb6ee6418..6b4c4e1ab7d 100644
--- a/grade/report/grader/lib.php
+++ b/grade/report/grader/lib.php
@@ -806,6 +806,8 @@ class grade_report_grader extends grade_report {
$meanselection = $this->get_pref('meanselection');
$shownumberofgrades = $this->get_pref('shownumberofgrades');
+ $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
+
$avghtml = '';
$avgcssclass = 'avg';
@@ -857,6 +859,12 @@ class grade_report_grader extends grade_report {
$columncount=1;
foreach ($this->items as $item) {
+ // If the user shouldn't see this grade_item, hide the average as well
+ if ($item->is_hidden() && !$canviewhidden) {
+ $avghtml .= '
- | ';
+ continue;
+ }
+
if (empty($sum_array[$item->id])) {
$sum_array[$item->id] = 0;
}
@@ -992,6 +1000,9 @@ class grade_report_grader extends grade_report {
$decimalpoints = $rangesdecimalpoints;
}
+ $grademin = 0;
+ $grademax = 100;
+
if ($displaytype == GRADE_DISPLAY_TYPE_REAL) {
$grademin = format_float($item->grademin, $decimalpoints);
$grademax = format_float($item->grademax, $decimalpoints);
diff --git a/grade/report/grader/preferences_form.php b/grade/report/grader/preferences_form.php
index bb8d25b904d..164de20a771 100644
--- a/grade/report/grader/preferences_form.php
+++ b/grade/report/grader/preferences_form.php
@@ -117,7 +117,7 @@ class grader_report_preferences_form extends moodleform {
$help_string = get_string("config$lang_string", 'grades');
// Replace the 'default' value with the site default language string
- if (!is_null($options) AND $options[GRADE_REPORT_PREFERENCE_DEFAULT] == 'default') {
+ if (!is_null($options) AND isset($options[GRADE_REPORT_PREFERENCE_DEFAULT]) && $options[GRADE_REPORT_PREFERENCE_DEFAULT] == 'default') {
$options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('sitedefault', 'grades', $default);
} elseif ($type == 'text') {
$help_string = get_string("config{$lang_string}default", 'grades', $default);
diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php
index e6e493ecd68..febffe8ca80 100644
--- a/lib/grade/grade_item.php
+++ b/lib/grade/grade_item.php
@@ -533,7 +533,7 @@ class grade_item extends grade_object {
* Returns the hidden state of this grade_item
* @return boolean hidden state
*/
- function is_hidden($userid=NULL) {
+ function is_hidden() {
return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
}