From 5dd0cb7bce882471359f50717946632819c4ff89 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 20 Oct 2014 15:24:45 +0800 Subject: [PATCH] MDL-47762 gradereport_user: Hide contribution and weights when relevant The contribution and weight columns should be hidden when the course total is because they can be used to compute the hidden course total. --- grade/report/lib.php | 7 +++++++ grade/report/user/lib.php | 20 +++++++++++++++---- grade/tests/behat/grade_aggregation.feature | 2 +- .../behat/grade_single_item_scales.feature | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/grade/report/lib.php b/grade/report/lib.php index af0208b9abb..b0aa35b76ae 100644 --- a/grade/report/lib.php +++ b/grade/report/lib.php @@ -510,6 +510,13 @@ abstract class grade_report { if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) { $aggregationweight = $hiding_affected['alteredaggregationweight'][$course_item->id]; } + + if (!$this->showtotalsifcontainhidden[$courseid]) { + // If the course total is hidden we must hide the weight otherwise + // it can be used to compute the course total. + $aggregationstatus = 'unknown'; + $aggregationweight = null; + } } } else if (!empty($hiding_affected['unknown'][$course_item->id])) { //not sure whether or not this item depends on a hidden item diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index 5508b379d3b..e02c99fcff2 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -739,9 +739,14 @@ class grade_report_user extends grade_report { // Multiply the normalised value by the weight // of all the categories higher in the tree. + $parent = null; do { if (!is_null($this->aggregationhints[$itemid]['weight'])) { $gradeval *= $this->aggregationhints[$itemid]['weight']; + } else if (empty($parent)) { + // If we are in the first loop, and the weight is null, then we cannot calculate the contribution. + $gradeval = null; + break; } // The second part of this if is to prevent infinite loops @@ -756,8 +761,11 @@ class grade_report_user extends grade_report { } } while ($parent); - // Convert to percent. - $gradeval *= 100; + // Finally multiply by the course grademax. + if (!is_null($gradeval)) { + // Convert to percent. + $gradeval *= 100; + } // Now we need to loop through the "built" table data and update the // contributions column for the current row. @@ -765,8 +773,12 @@ class grade_report_user extends grade_report { foreach ($this->tabledata as $key => $row) { if (isset($row['itemname']) && ($row['itemname']['id'] == $header_row)) { // Found it - update the column. - $decimals = $grade_object->get_decimals(); - $this->tabledata[$key]['contributiontocoursetotal']['content'] = format_float($gradeval, $decimals, true) . ' %'; + $content = '-'; + if (!is_null($gradeval)) { + $decimals = $grade_object->get_decimals(); + $content = format_float($gradeval, $decimals, true) . ' %'; + } + $this->tabledata[$key]['contributiontocoursetotal']['content'] = $content; break; } } diff --git a/grade/tests/behat/grade_aggregation.feature b/grade/tests/behat/grade_aggregation.feature index e8b5fded85d..4e75b01a5bd 100644 --- a/grade/tests/behat/grade_aggregation.feature +++ b/grade/tests/behat/grade_aggregation.feature @@ -399,7 +399,7 @@ Feature: We can use calculated grade totals | Test assignment seven | 21.43 % | - | 0–15 | 0.00 % | | Test assignment eight | 66.67 % | 10.00 (50.00 %) | 0–20 | 1.60 % | | Test assignment nine | 33.33 % | 5.00 (50.00 %) | 0–10 | 0.80 % | - | Test assignment ten | -( Empty ) | - | 0–15 | 0.00 % | + | Test assignment ten | 0.00 %( Empty ) | - | 0–15 | 0.00 % | | Test assignment one | 48.00 % | 60.00 (20.00 %) | 0–300 | 9.60 % | | Test assignment two | 16.00 % | 20.00 (20.00 %) | 0–100 | 3.20 % | | Test assignment three | 24.00 %( Extra credit ) | 40.00 (26.67 %) | 0–150 | 6.40 % | diff --git a/grade/tests/behat/grade_single_item_scales.feature b/grade/tests/behat/grade_single_item_scales.feature index ce00516ce3a..5a83d48565e 100644 --- a/grade/tests/behat/grade_single_item_scales.feature +++ b/grade/tests/behat/grade_single_item_scales.feature @@ -76,7 +76,7 @@ Feature: View gradebook when single item scales are used And I set the field "Select all or one user" to "Student 2" And the following should exist in the "user-grade" table: | Grade item | Grade | Range | Contribution to course total | - | Test assignment one | - | Ace!–Ace! | 0.00 % | + | Test assignment one | - | Ace!–Ace! | - | | Category total | - | 0–1 | - | | Course total | - | 0–1 | - | And I set the field "jump" to "Categories and items"