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.
This commit is contained in:
Frederic Massart 2014-10-20 15:24:45 +08:00 committed by Eloy Lafuente (stronk7)
parent 444ff60526
commit 5dd0cb7bce
4 changed files with 25 additions and 6 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -399,7 +399,7 @@ Feature: We can use calculated grade totals
| Test assignment seven | 21.43 % | - | 015 | 0.00 % |
| Test assignment eight | 66.67 % | 10.00 (50.00 %) | 020 | 1.60 % |
| Test assignment nine | 33.33 % | 5.00 (50.00 %) | 010 | 0.80 % |
| Test assignment ten | -( Empty ) | - | 015 | 0.00 % |
| Test assignment ten | 0.00 %( Empty ) | - | 015 | 0.00 % |
| Test assignment one | 48.00 % | 60.00 (20.00 %) | 0300 | 9.60 % |
| Test assignment two | 16.00 % | 20.00 (20.00 %) | 0100 | 3.20 % |
| Test assignment three | 24.00 %( Extra credit ) | 40.00 (26.67 %) | 0150 | 6.40 % |

View File

@ -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 | - | 01 | - |
| Course total | - | 01 | - |
And I set the field "jump" to "Categories and items"