From 4e8013e418d7ed1f87ce35bf2db30ca32d9685cc Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 2 Aug 2022 17:21:04 +0200 Subject: [PATCH] MDL-75358 reportbuilder: display nulls as empty cells for numeric/bool --- reportbuilder/classes/local/helpers/format.php | 12 +++++++++--- reportbuilder/classes/local/report/column.php | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/reportbuilder/classes/local/helpers/format.php b/reportbuilder/classes/local/helpers/format.php index 2662cd5bee8..722856acecd 100644 --- a/reportbuilder/classes/local/helpers/format.php +++ b/reportbuilder/classes/local/helpers/format.php @@ -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)); } } diff --git a/reportbuilder/classes/local/report/column.php b/reportbuilder/classes/local/report/column.php index d0177c3e4e6..159c80caeeb 100644 --- a/reportbuilder/classes/local/report/column.php +++ b/reportbuilder/classes/local/report/column.php @@ -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()) {