mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-73824 gradebook: Stricter float check to some gradelib functions
It has been detected that, right now, some localised floats are being passed to those functions (say comma separator, say thousands) and that's leading to all sort of problems later when comparing, processing or storing those "wrong-floats" (user entered). This just makes all those functions to be stricter, so any attempt of passing to them a wrong float will fail with a clear TypeError. Any existing case must be converted to a corrrect (X.Y) format, using unformat_float() or PARAM_LOCALISEDFLOAT before any processing. Localised floats cannot be used. Also, fix all the places where those functions are called from files having strict_types enabled because, with that, now float-like strings are not accepted any more. Luckily, there is only case, within the grade/classes/component_gradeitem.php file, and it has been fixed by casting the float-like string coming from DB to float.
This commit is contained in:
parent
1d99ba19a2
commit
e2821bf1ce
3 changed files with 28 additions and 17 deletions
|
@ -405,6 +405,7 @@ abstract class component_gradeitem {
|
|||
if ($grade = $this->get_grade_for_user($gradeduser, $grader)) {
|
||||
$gradeitem = $this->get_grade_item();
|
||||
if (!$this->is_using_scale()) {
|
||||
$grade->grade = !is_null($grade->grade) ? (float)$grade->grade : null; // Cast non-null values, keeping nulls.
|
||||
$grade->usergrade = grade_format_gradevalue($grade->grade, $gradeitem);
|
||||
$grade->maxgrade = format_float($gradeitem->grademax, $gradeitem->get_decimals());
|
||||
// If displaying the raw grade, also display the total value.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue