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:
Eloy Lafuente (stronk7) 2022-02-15 10:15:16 +01:00
parent 1d99ba19a2
commit e2821bf1ce
3 changed files with 28 additions and 17 deletions

View file

@ -2,6 +2,16 @@ This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.
=== 4.0 ===
* To better detect wrong floats (like, for example, unformatted, using local-dependent separators ones) a number of
gradebook functions now have stricter float type checking. All them will require now the "float" being passed to be
a correct float value (numeric or string). Usually, that's achieved by using unformat_float() or
PARAM_LOCALISEDFLOAT for all the user-entered grades before any processing on them. Functions affected are:
- grade_format_gradevalue(), $value param (keeping it as optional/nullable).
- grade_format_gradevalue_real(), $value param (keeping it as optional/nullable).
- grade_format_gradevalue_percentage(), $value param (keeping it as optional/nullable).
- grade_format_gradevalue_letter(), $value param (keeping it as optional/nullable).
- grade_floats_different(), $f1 and $f2 params (keeping them as optional/nullable).
- grade_floats_equal(), $f1 and $f2 params (keeping them as optional/nullable).
* The method action_menu->set_alignment() has been deprecated, please use action_menu->set_menu_left if you need a dropdown
to align to the left of the dropdown button.
* The $OUTPUT->should_display_main_logo() function has been deprecated and should no longer be used.