diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index 71356040a8b..17846bfcb23 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -474,8 +474,8 @@ class grade_report_user extends grade_report { $hint = $grade_grade->get_aggregation_hint($grade_object); if ($hint) { // This obliterates the weight because it provides a more informative description. - if (intval($hint)) { - $hint = format_float(intval($hint) / 100.0, 2) . ' %'; + if (is_numeric($hint)) { + $hint = format_float($hint * 100.0, 2) . ' %'; } $data['weight']['content'] = $hint; } @@ -616,7 +616,7 @@ class grade_report_user extends grade_report { $hint = $grade_grade->get_aggregation_hint($grade_object); if ($hint && is_numeric($hint)) { $me = $grade_grade->grade_item; - $percentoftotal = intval($hint) / 10000.0; + $percentoftotal = $hint; $validpercent = true; $limit = 0; $parent = null; @@ -641,7 +641,7 @@ class grade_report_user extends grade_report { $validpercent = $parentgradeitem->is_course_item(); continue; } - $thispercent = intval($hint) / 10000.0; + $thispercent = $hint; $percentoftotal *= $thispercent; $limit++; if ($limit > 20) { diff --git a/lib/db/install.xml b/lib/db/install.xml index 10bd6f22a58..8102dd53477 100755 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1764,7 +1764,8 @@ - + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2e9866b5542..1d8c35c8aed 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3719,21 +3719,6 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2014072400.01); } - if ($oldversion < 2014080700.00) { - - // Define field usedinaggregation to be added to grade_grades. - $table = new xmldb_table('grade_grades'); - $field = new xmldb_field('usedinaggregation', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'unknown', 'timemodified'); - - // Conditionally launch add field usedinaggregation. - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - // Main savepoint reached. - upgrade_main_savepoint(true, 2014080700.00); - } - if ($oldversion < 2014080801.00) { // Define index behaviour (not unique) to be added to question_attempts. @@ -3852,5 +3837,27 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2014100100.00); } + if ($oldversion < 2014082700.00) { + + // Define field aggregationstatus to be added to grade_grades. + $table = new xmldb_table('grade_grades'); + $field = new xmldb_field('aggregationstatus', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'unknown', 'timemodified'); + + // Conditionally launch add field aggregationstatus. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('aggregationweight', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'aggregationstatus'); + + // Conditionally launch add field aggregationweight. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2014082700.00); + } + return true; } diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index d8a4c661eb7..143d3aef878 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -675,14 +675,22 @@ class grade_category extends grade_object { if (!empty($usedweights)) { // The usedweights items are updated individually to record the weights. foreach ($usedweights as $gradeitemid => $contribution) { - // Convert contribution to a 4 digit integer so there are no localization problems. - $contribution = intval($contribution * 10000); $DB->set_field_select('grade_grades', - 'usedinaggregation', + 'aggregationweight', $contribution, "itemid = :itemid AND userid = :userid", array('itemid'=>$gradeitemid, 'userid'=>$userid)); } + + // Now set the status flag for all these weights. + list($itemsql, $itemlist) = $DB->get_in_or_equal(array_keys($usedweights), SQL_PARAMS_NAMED, 'g'); + $itemlist['userid'] = $userid; + + $DB->set_field_select('grade_grades', + 'aggregationstatus', + 'used', + "itemid $itemsql AND userid = :userid", + $itemlist); } // No value. @@ -692,7 +700,7 @@ class grade_category extends grade_object { $itemlist['userid'] = $userid; $DB->set_field_select('grade_grades', - 'usedinaggregation', + 'aggregationstatus', 'novalue', "itemid $itemsql AND userid = :userid", $itemlist); @@ -705,7 +713,7 @@ class grade_category extends grade_object { $itemlist['userid'] = $userid; $DB->set_field_select('grade_grades', - 'usedinaggregation', + 'aggregationstatus', 'dropped', "itemid $itemsql AND userid = :userid", $itemlist); diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index 70d43d93d70..a2e6a6a79ac 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -50,7 +50,7 @@ class grade_grade extends grade_object { public $required_fields = array('id', 'itemid', 'userid', 'rawgrade', 'rawgrademax', 'rawgrademin', 'rawscaleid', 'usermodified', 'finalgrade', 'hidden', 'locked', 'locktime', 'exported', 'overridden', 'excluded', 'timecreated', - 'timemodified', 'usedinaggregation'); + 'timemodified', 'aggregationstatus', 'aggregationweight'); /** * Array of optional fields with default values (these should match db defaults) @@ -161,11 +161,16 @@ class grade_grade extends grade_object { public $timemodified = null; /** - * Used in aggregation flag. Can be one of 'unknown', 'dropped', 'novalue' or a specific weighting. - * @var string $usedinaggregation + * Aggregation status flag. Can be one of 'unknown', 'dropped', 'novalue' or 'used'. + * @var string $aggregationstatus */ - public $usedinaggregation = 'unknown'; + public $aggregationstatus = 'unknown'; + /** + * Aggregation weight is the specific weight used in the aggregation calculation for this grade. + * @var float $aggregationweight + */ + public $aggregationweight = null; /** * Returns array of grades for given grade_item+users @@ -292,23 +297,43 @@ class grade_grade extends grade_object { return $this->timecreated; } + /** + * Returns the weight this grade contributed to the aggregated grade + * + * @return float|null + */ + public function get_aggregationweight() { + return $this->aggregationweight; + } + + /** + * Set aggregationweight. + * + * @param float $aggregationweight + * @return void + */ + public function set_aggregationweight($aggregationweight) { + $this->aggregationweight = $aggregationweight; + $this->update(); + } + /** * Returns the info on how this value was used in the aggregated grade * * @return string One of 'dropped', 'excluded', 'novalue' or a specific weighting */ - public function get_usedinaggregation() { - return $this->usedinaggregation; + public function get_aggregationstatus() { + return $this->aggregationstatus; } /** - * Set usedinaggregation flag + * Set aggregationstatus flag * - * @param string $usedinaggregation + * @param string $aggregationstatus * @return void */ - public function set_usedinaggregation($usedinaggregation) { - $this->usedinaggregation = $usedinaggregation; + public function set_aggregationstatus($aggregationstatus) { + $this->aggregationstatus = $aggregationstatus; $this->update(); } @@ -991,13 +1016,13 @@ class grade_grade extends grade_object { // Is it dropped? if ($hint == '') { - $aggr = $this->get_usedinaggregation(); + $aggr = $this->get_aggregationstatus(); if ($aggr == 'dropped') { $hint = get_string('dropped', 'grades'); - } else if ($aggr == 'novalue') { - $hint = '-'; + } else if ($aggr == 'used') { + $hint = $this->get_aggregationweight(); } else if ($aggr != 'unknown') { - $hint = $aggr; + $hint = '-'; } }