mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-47064 Grades: Peer review cleanups
Changes include: * Search for existing items to reduce DB queries in grade_category::aggregate_grades * Comments improvements * Move brackets to be part of lang string * Convert aggregationhints to be a class variable instead of passing it around Part of: MDL-46576
This commit is contained in:
parent
6070e53313
commit
ee07a54be0
4 changed files with 67 additions and 53 deletions
|
@ -480,28 +480,28 @@ abstract class grade_report {
|
|||
|
||||
//if the item definitely depends on a hidden item
|
||||
if (array_key_exists($course_item->id, $hiding_affected['altered']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredgrademin']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredgrademax']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredgrademin']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredgrademax']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus']) ||
|
||||
array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
|
||||
if (!$this->showtotalsifcontainhidden[$courseid]) {
|
||||
//hide the grade
|
||||
$finalgrade = null;
|
||||
} else {
|
||||
//use reprocessed marks that exclude hidden items
|
||||
if (!empty($hiding_affected['altered'][$course_item->id])) {
|
||||
if (isset($hiding_affected['altered'][$course_item->id])) {
|
||||
$finalgrade = $hiding_affected['altered'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredgrademin'][$course_item->id])) {
|
||||
if (isset($hiding_affected['alteredgrademin'][$course_item->id])) {
|
||||
$grademin = $hiding_affected['alteredgrademin'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredgrademax'][$course_item->id])) {
|
||||
if (isset($hiding_affected['alteredgrademax'][$course_item->id])) {
|
||||
$grademax = $hiding_affected['alteredgrademax'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredaggregationstatus'][$course_item->id])) {
|
||||
if (isset($hiding_affected['alteredaggregationstatus'][$course_item->id])) {
|
||||
$aggregationstatus = $hiding_affected['alteredaggregationstatus'][$course_item->id];
|
||||
}
|
||||
if (!empty($hiding_affected['alteredaggregationweight'][$course_item->id])) {
|
||||
if (isset($hiding_affected['alteredaggregationweight'][$course_item->id])) {
|
||||
$aggregationweight = $hiding_affected['alteredaggregationweight'][$course_item->id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,6 +176,15 @@ class grade_report_user extends grade_report {
|
|||
*/
|
||||
protected $viewasuser = false;
|
||||
|
||||
/**
|
||||
* An array that collects the aggregationhints for every
|
||||
* grade_item. The hints contain grade, grademin, grademax
|
||||
* status, weight and parent.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aggregationhints = array();
|
||||
|
||||
/**
|
||||
* Constructor. Sets local copies of user preferences and initialises grade_tree.
|
||||
* @param int $courseid
|
||||
|
@ -354,11 +363,8 @@ class grade_report_user extends grade_report {
|
|||
* Fill the table with data.
|
||||
*
|
||||
* @param $element - An array containing the table data for the current row.
|
||||
* @param $aggregationhints - An array that collects the aggregationhints for every
|
||||
* grade_item. The hints contain grade, grademin, grademax
|
||||
* status, weight and parent.
|
||||
*/
|
||||
private function fill_table_recursive(&$element, &$aggregationhints = array()) {
|
||||
private function fill_table_recursive(&$element) {
|
||||
global $DB, $CFG;
|
||||
|
||||
$type = $element['type'];
|
||||
|
@ -494,7 +500,7 @@ class grade_report_user extends grade_report {
|
|||
$data['weight']['content'] = format_float($hint['weight'] * 100.0, 2) . ' %';
|
||||
}
|
||||
if ($hint['status'] != 'used' && $hint['status'] != 'unknown') {
|
||||
$data['weight']['content'] .= '<br/>( ' . get_string('aggregationhint' . $hint['status'], 'grades') . ' )';
|
||||
$data['weight']['content'] .= '<br>' . get_string('aggregationhint' . $hint['status'], 'grades');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -637,7 +643,7 @@ class grade_report_user extends grade_report {
|
|||
$parent = $parent->load_parent_category();
|
||||
}
|
||||
$hint['parent'] = $parent->load_grade_item()->id;
|
||||
$aggregationhints[$grade_grade->itemid] = $hint;
|
||||
$this->aggregationhints[$grade_grade->itemid] = $hint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +670,7 @@ class grade_report_user extends grade_report {
|
|||
/// Recursively iterate through all child elements
|
||||
if (isset($element['children'])) {
|
||||
foreach ($element['children'] as $key=>$child) {
|
||||
$this->fill_table_recursive($element['children'][$key], $aggregationhints);
|
||||
$this->fill_table_recursive($element['children'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,7 +679,7 @@ class grade_report_user extends grade_report {
|
|||
if ($this->showcontributiontocoursetotal && ($type == 'category' && $depth == 1)) {
|
||||
// We should have collected all the hints by now - walk the tree again and build the contributions column.
|
||||
|
||||
$this->fill_contributions_column($element, $aggregationhints);
|
||||
$this->fill_contributions_column($element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -683,16 +689,13 @@ class grade_report_user extends grade_report {
|
|||
* grade_item.
|
||||
*
|
||||
* @param $element - An array containing the table data for the current row.
|
||||
* @param $aggregationhints - An array that collects the aggregationhints for every
|
||||
* grade_item. The hints contain grade, grademin, grademax
|
||||
* status, weight and parent.
|
||||
*/
|
||||
public function fill_contributions_column($element, $aggregationhints) {
|
||||
public function fill_contributions_column($element) {
|
||||
|
||||
/// Recursively iterate through all child elements
|
||||
// Recursively iterate through all child elements.
|
||||
if (isset($element['children'])) {
|
||||
foreach ($element['children'] as $key=>$child) {
|
||||
$this->fill_contributions_column($element['children'][$key], $aggregationhints);
|
||||
$this->fill_contributions_column($element['children'][$key]);
|
||||
}
|
||||
} else if ($element['type'] == 'item') {
|
||||
// This is a grade item (We don't do this for categories or we would double count).
|
||||
|
@ -700,40 +703,38 @@ class grade_report_user extends grade_report {
|
|||
$itemid = $grade_object->id;
|
||||
|
||||
// Ignore anything with no hint - e.g. a hidden row.
|
||||
if (isset($aggregationhints[$itemid])) {
|
||||
if (isset($this->aggregationhints[$itemid])) {
|
||||
|
||||
// Normalise the gradeval.
|
||||
$graderange = $aggregationhints[$itemid]['grademax'] - $aggregationhints[$itemid]['grademin'];
|
||||
$gradeval = ($aggregationhints[$itemid]['grade'] - $aggregationhints[$itemid]['grademin']) / $graderange;
|
||||
$graderange = $this->aggregationhints[$itemid]['grademax'] - $this->aggregationhints[$itemid]['grademin'];
|
||||
$gradeval = ($this->aggregationhints[$itemid]['grade'] - $this->aggregationhints[$itemid]['grademin']) / $graderange;
|
||||
|
||||
// Multiply the normalised value by the weight
|
||||
// of all the categories higher in the tree.
|
||||
$parent = $aggregationhints[$itemid]['parent'];
|
||||
do {
|
||||
if (!is_null($aggregationhints[$itemid]['weight'])) {
|
||||
$gradeval *= $aggregationhints[$itemid]['weight'];
|
||||
if (!is_null($this->aggregationhints[$itemid]['weight'])) {
|
||||
$gradeval *= $this->aggregationhints[$itemid]['weight'];
|
||||
}
|
||||
|
||||
// The second part of this if is to prevent infinite loops
|
||||
// in case of crazy data.
|
||||
if (isset($aggregationhints[$itemid]['parent']) &&
|
||||
$aggregationhints[$itemid]['parent'] != $itemid) {
|
||||
$parent = $aggregationhints[$itemid]['parent'];
|
||||
if (isset($this->aggregationhints[$itemid]['parent']) &&
|
||||
$this->aggregationhints[$itemid]['parent'] != $itemid) {
|
||||
$parent = $this->aggregationhints[$itemid]['parent'];
|
||||
$itemid = $parent;
|
||||
} else {
|
||||
// We are at the top of the tree
|
||||
// We are at the top of the tree.
|
||||
$parent = false;
|
||||
}
|
||||
} while ($parent);
|
||||
// Finally multiply by the course grademax.
|
||||
$gradeval *= $aggregationhints[$itemid]['grademax'];
|
||||
$gradeval *= $this->aggregationhints[$itemid]['grademax'];
|
||||
|
||||
// Now we need to loop through the "built" table data and update the
|
||||
// contributions column for the current row.
|
||||
$header_row = "row_{$grade_object->id}_{$this->user->id}";
|
||||
foreach ($this->tabledata as $key => $row) {
|
||||
if (isset($row['itemname']) &&
|
||||
($row['itemname']['id'] == $header_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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue