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

This commit is contained in:
Marina Glancy
2022-09-20 18:18:38 +02:00
parent b077af7e89
commit dcc44ae4c0
3 changed files with 19 additions and 9 deletions
@@ -63,11 +63,11 @@ class completion {
/**
* Return number of days for methods daystakingcourse and daysuntilcompletion
*
* @param int $value
* @param int|null $value
* @param stdClass $row
* @return int|null
*/
public static function get_days(int $value, stdClass $row): ?int {
public static function get_days(?int $value, stdClass $row): ?int {
// Do not show anything if there is no userid.
if (!$row->userid) {
return null;
+12 -6
View File
@@ -32,32 +32,38 @@ 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
*/
public static function userdate(int $value, stdClass $row, ?string $format = null): string {
public static function userdate(?int $value, stdClass $row, ?string $format = null): string {
return $value ? userdate($value, $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(bool $value): string {
public static function boolean_as_text(?bool $value): string {
if ($value === null) {
return '';
}
return $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(float $value): string {
public static function percent(?float $value): string {
if ($value === null) {
return '';
}
return get_string('percents', 'moodle', format_float($value));
}
}
@@ -479,7 +479,8 @@ final class column {
* fields, and $additionalarguments are those passed on from this method):
*
* The type of the $value parameter passed to the callback is determined by calling {@see set_type}, this type is preserved
* if the column is part of a report source and is being aggregated
* if the column is part of a report source and is being aggregated.
* 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 {
*/
public static function get_default_value(array $values, int $columntype) {
$value = reset($values);
if ($value === null) {
return $value;
}
// Ensure default value is cast to it's strict type.
switch ($columntype) {