$item->aggregationcoef = 0;
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
+ $item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
} else {
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
}
unset($data->locked);
unset($data->locktime);
- $convert = array('gradepass', 'aggregationcoef');
+ $convert = array('gradepass', 'aggregationcoef', 'aggregationcoef2');
foreach ($convert as $param) {
if (property_exists($data, $param)) {
$data->$param = unformat_float($data->$param);
}
}
+ if (isset($data->aggregationcoef2) && $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
+ $data->aggregationcoef2 = $data->aggregationcoef2 / 100.0;
+ }
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
grade_item::set_properties($grade_item, $data);
$mform->addHelpButton('cmid', 'linkedactivity', 'grades');
$mform->setDefault('cmid', 0);
+ $mform->addElement('advcheckbox', 'weightoverride', get_string('adjustedweight', 'grades'));
+ $mform->addHelpButton('weightoverride', 'weightoverride', 'grades');
+
+ $mform->addElement('text', 'aggregationcoef2', get_string('weight', 'grades'));
+ $mform->addHelpButton('aggregationcoef2', 'weight', 'grades');
+ $mform->setType('aggregationcoef2', PARAM_RAW);
+ $mform->disabledIf('aggregationcoef2', 'weightoverride');
+
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
}
if ($coefstring !== '') {
- if ($coefstring == 'aggregationcoefextrasum') {
+ if ($coefstring == 'aggregationcoefextrasum' || $coefstring == 'aggregationcoefextraweightsum') {
// advcheckbox is not compatible with disabledIf!
+ $coefstring = 'aggregationcoefextrasum';
$mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
} else {
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
$mform->addHelpButton('aggregationcoef', $aggcoef, 'grades');
}
}
+ // Remove fields used by natural weighting if the parent category is not using natural weighting.
+ if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
+ if ($mform->elementExists('weightoverride')) {
+ $mform->removeElement('weightoverride');
+ }
+ if ($mform->elementExists('aggregationcoef2')) {
+ $mform->removeElement('aggregationcoef2');
+ }
+ }
}
}