From 6df5b04ec76a9b7fc6ff4d80e5a4891796e74215 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Thu, 4 Oct 2007 08:02:00 +0000 Subject: [PATCH] MDL-11576 New grade_item method has_hidden_grades(), which returns a simple count of hidden grades for the item. --- grade/report/grader/lib.php | 4 +++- lib/grade/grade_item.php | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index a68bc33cf6c..21bb72a64d0 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -859,9 +859,11 @@ class grade_report_grader extends grade_report { $avghtml = ''.$straverage.''; $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) { + // MDL-11576 If any of the grades are hidden and the user doesn't have permission to view them, hide average as well + if (($item->is_hidden() || $item->has_hidden_grades()) && !$canviewhidden) { $avghtml .= ' - '; continue; } diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index c3e4b464314..a6387b29bd2 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -564,6 +564,14 @@ class grade_item extends grade_object { } } } + + /** + * Returns the number of grades that are hidden. + * @param return int Number of hidden grades + */ + function has_hidden_grades() { + return count_records('grade_grades', 'itemid', $this->id, 'hidden', 1); + } /** * Mark regrading as finished successfully.