$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;
}
$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;
$validpercent = $parentgradeitem->is_course_item();
continue;
}
- $thispercent = intval($hint) / 10000.0;
+ $thispercent = $hint;
$percentoftotal *= $thispercent;
$limit++;
if ($limit > 20) {
<FIELD NAME="informationformat" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="format of information text"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="the time this grade was first created"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="the time this grade was last modified"/>
- <FIELD NAME="usedinaggregation" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="unknown" SEQUENCE="false" COMMENT="One of several values describing how this grade_grade was used when calculating the aggregation. Possible values are "unknown", "dropped", "novalue", "included""/>
+ <FIELD NAME="aggregationstatus" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="unknown" SEQUENCE="false" COMMENT="One of several values describing how this grade_grade was used when calculating the aggregation. Possible values are "unknown", "dropped", "novalue", "used""/>
+ <FIELD NAME="aggregationweight" TYPE="number" LENGTH="10" NOTNULL="false" SEQUENCE="false" DECIMALS="5" COMMENT="If the aggregationstatus == 'included', then this is the percent this item contributed to the aggregation."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
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.
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;
}
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.
$itemlist['userid'] = $userid;
$DB->set_field_select('grade_grades',
- 'usedinaggregation',
+ 'aggregationstatus',
'novalue',
"itemid $itemsql AND userid = :userid",
$itemlist);
$itemlist['userid'] = $userid;
$DB->set_field_select('grade_grades',
- 'usedinaggregation',
+ 'aggregationstatus',
'dropped',
"itemid $itemsql AND userid = :userid",
$itemlist);
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)
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
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();
}
// 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 = '-';
}
}