MDL-47006 core_grades: Fix float formatting

Part of MDL-46576
This commit is contained in:
John Okely 2014-09-19 10:29:04 +08:00 committed by Adrian Greeve
parent d32b293eac
commit 0281770091
4 changed files with 17 additions and 12 deletions

View file

@ -108,10 +108,6 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $mform->get_data(false)) {
if (isset($data->grade_item_weight)) {
$data->grade_item_aggregationcoef2 = $data->grade_item_weight / 100.0;
unset($data->grade_item_weight);
}
// If no fullname is entered for a course category, put ? in the DB
if (!isset($data->fullname) || $data->fullname == '') {
$data->fullname = '?';
@ -174,6 +170,10 @@ if ($mform->is_cancelled()) {
$itemdata->$param = unformat_float($itemdata->$param);
}
}
if (isset($itemdata->weight)) {
$temdata->aggregationcoef2 = $itemdata->weight / 100.0;
unset($itemdata->weight);
}
// When creating a new category, a number of grade item fields are filled out automatically, and are required.
// If the user leaves these fields empty during creation of a category, we let the default values take effect

View file

@ -161,7 +161,7 @@ class edit_category_form extends moodleform {
$mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
}
$mform->addElement('checkbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades');
$mform->addElement('text', 'grade_item_weight', get_string('weight', 'grades'));

View file

@ -279,9 +279,10 @@ if ($data = data_submitted() and confirm_sesskey()) {
if (round($grade_item->aggregationcoef2, 4) != round($value, 4)) {
$grade_item->weightoverride = 1;
}
$param = 'aggregationcoef2';
$grade_item->aggregationcoef2 = $value;
} else {
$grade_item->$param = $value;
}
$grade_item->$param = $value;
$grade_item->update();

View file

@ -110,10 +110,6 @@ if ($mform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $mform->get_data(false)) {
if (isset($data->weight)) {
$data->aggregationcoef2 = $data->weight / 100.0;
unset($data->weight);
}
// If unset, give the aggregationcoef a default based on parent aggregation method
if (!isset($data->aggregationcoef) || $data->aggregationcoef == '') {
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
@ -141,12 +137,20 @@ if ($mform->is_cancelled()) {
unset($data->locked);
unset($data->locktime);
$convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef', 'weight');
$convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'weight');
foreach ($convert as $param) {
if (property_exists($data, $param)) {
$data->$param = unformat_float($data->$param);
}
}
if (isset($data->weight)) {
if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$data->aggregationcoef2 = $data->weight / 100.0;
} else if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$data->aggregationcoef = $data->weight;
}
unset($data->weight);
}
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
$previouslyoverridden = $grade_item->weightoverride;