Skip to content
Browse files

MDL-33498: Correct use of unformat_float for mod_assign decimal grades

This was affecting locales that use , instead of . in floating point numbers.
  • Loading branch information...
1 parent 4a5be0e commit 4913af936f273d64273da69eee85526572706343 Damyon Wiese committed Jun 5, 2012
Showing with 8 additions and 8 deletions.
  1. +3 −3 mod/assign/gradeform.php
  2. +5 −5 mod/assign/locallib.php
View
6 mod/assign/gradeform.php
@@ -73,11 +73,11 @@ function validation($data, $files) {
}
if ($this->assignment->get_instance()->grade > 0) {
- if (!is_numeric($data['grade']) and (!empty($data['grade']))) {
+ if (unformat_float($data['grade']) === null && (!empty($data['grade']))) {
$errors['grade'] = get_string('invalidfloatforgrade', 'assign', $data['grade']);
- } else if ($data['grade'] > $this->assignment->get_instance()->grade) {
+ } else if (unformat_float($data['grade']) > $this->assignment->get_instance()->grade) {
$errors['grade'] = get_string('gradeabovemaximum', 'assign', $this->assignment->get_instance()->grade);
- } else if ($data['grade'] < 0) {
+ } else if (unformat_float($data['grade']) < 0) {
$errors['grade'] = get_string('gradebelowzero', 'assign');
}
} else {
View
10 mod/assign/locallib.php
@@ -895,7 +895,7 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
if ($this->get_instance()->grade >= 0) {
// Normal number
if ($editing) {
- $o = '<input type="text" name="quickgrade_' . $userid . '" value="' . $grade . '" size="6" maxlength="10" class="quickgrade"/>';
+ $o = '<input type="text" name="quickgrade_' . $userid . '" value="' . format_float($grade) . '" size="6" maxlength="10" class="quickgrade"/>';
$o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade,2);
$o .= '<input type="hidden" name="grademodified_' . $userid . '" value="' . $modified . '"/>';
return $o;
@@ -2531,7 +2531,7 @@ private function process_save_quick_grades() {
// gather the userid, updated grade and last modified value
$record = new stdClass();
$record->userid = $userid;
- $record->grade = required_param('quickgrade_' . $userid, PARAM_INT);
+ $record->grade = unformat_float(required_param('quickgrade_' . $record->userid, PARAM_TEXT));
$record->lastmodified = $modified;
$record->gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, array($userid));
$users[$userid] = $record;
@@ -2560,7 +2560,7 @@ private function process_save_quick_grades() {
if ($CFG->enableoutcomes) {
foreach ($modified->gradinginfo->outcomes as $outcomeid => $outcome) {
$oldoutcome = $outcome->grades[$modified->userid]->grade;
- $newoutcome = optional_param('outcome_' . $outcomeid . '_' . $modified->userid, -1, PARAM_INT);
+ $newoutcome = optional_param('outcome_' . $outcomeid . '_' . $modified->userid, -1, PARAM_FLOAT);
if ($oldoutcome != $newoutcome) {
// can't check modified time for outcomes because it is not reported
$modifiedusers[$modified->userid] = $modified;
@@ -2605,7 +2605,7 @@ private function process_save_quick_grades() {
// ok - ready to process the updates
foreach ($modifiedusers as $userid => $modified) {
$grade = $this->get_user_grade($userid, true);
- $grade->grade= grade_floatval($modified->grade);
+ $grade->grade= grade_floatval(unformat_float($modified->grade));
$grade->grader= $USER->id;
$this->update_grade($grade);
@@ -3180,7 +3180,7 @@ private function process_save_grade(&$mform) {
} else {
// handle the case when grade is set to No Grade
if (isset($formdata->grade)) {
- $grade->grade= grade_floatval($formdata->grade);
+ $grade->grade= grade_floatval(unformat_float($formdata->grade));
}
}
$grade->grader= $USER->id;

0 comments on commit 4913af9

Please sign in to comment.
Something went wrong with that request. Please try again.