MDL-75358 reportbuilder: display nulls as empty cells for numeric/bool

This commit is contained in:
Marina Glancy
2022-09-19 14:43:56 +02:00
parent 844abeaf5d
commit 4e8013e418
2 changed files with 13 additions and 3 deletions
@@ -35,7 +35,7 @@ class format {
/**
* Returns formatted date.
*
* @param int $value Unix timestamp
* @param int|null $value Unix timestamp
* @param stdClass $row
* @param string|null $format Format string for strftime
* @return string
@@ -47,20 +47,26 @@ class format {
/**
* Returns yes/no string depending on the given value
*
* @param bool $value
* @param bool|null $value
* @return string
*/
public static function boolean_as_text($value): string {
if ($value === null) {
return '';
}
return (bool) $value ? get_string('yes') : get_string('no');
}
/**
* Returns float value as a percentage
*
* @param float $value
* @param float|null $value
* @return string
*/
public static function percent($value): string {
if ($value === null) {
return '';
}
return get_string('percents', 'moodle', format_float((float) $value));
}
}
@@ -481,6 +481,7 @@ final class column {
* The type of the $value parameter passed to the callback is determined by calling {@see set_type}, however note that
* if the column is part of a report source and can be aggregated using one of the "Group concatenation" methods then the
* type should be omitted if it's not string
* For entities that can to be left joined to a report, the first argument to their column callbacks must be nullable.
*
* function($value, stdClass $row[, $additionalarguments]): string
*
@@ -649,6 +650,9 @@ final class column {
*/
private function get_default_value(array $values) {
$value = reset($values);
if ($value === null) {
return $value;
}
// Ensure default value is cast to it's strict type.
switch ($this->get_type()) {