MDL-75358 reportbuilder: display nulls as empty cells in aggregation

This commit is contained in:
Marina Glancy 2022-08-02 18:26:37 +02:00
parent dcc44ae4c0
commit 4bb042c352
5 changed files with 18 additions and 3 deletions

View File

@ -76,6 +76,9 @@ class avg extends base {
* @return mixed
*/
public static function format_value($value, array $values, array $callbacks, int $columntype) {
if (reset($values) === null) {
return null;
}
if ($columntype === column::TYPE_BOOLEAN || empty($callbacks)) {
return format_float((float) reset($values), 1);
}

View File

@ -111,6 +111,11 @@ class groupconcat extends base {
* @return mixed
*/
public static function format_value($value, array $values, array $callbacks, int $columntype) {
$firstvalue = reset($values);
if ($firstvalue === null) {
return '';
}
$formattedvalues = [];
// Store original names of all values that would be present without aggregation.
@ -118,7 +123,7 @@ class groupconcat extends base {
$valuenamescount = count($valuenames);
// Loop over each extracted value from the concatenated string.
$values = explode(self::FIELD_VALUE_DELIMETER, (string) reset($values));
$values = explode(self::FIELD_VALUE_DELIMETER, (string)$firstvalue);
foreach ($values as $value) {
// Ensure we have equal number of value names/data, account for truncation by DB.

View File

@ -73,6 +73,9 @@ class percent extends base {
* @return string
*/
public static function format_value($value, array $values, array $callbacks, int $columntype): string {
if (reset($values) === null) {
return '';
}
return format::percent((float) reset($values));
}
}

View File

@ -76,9 +76,13 @@ class sum extends base {
* @return mixed
*/
public static function format_value($value, array $values, array $callbacks, int $columntype) {
$firstvalue = reset($values);
if ($firstvalue === null) {
return null;
}
if ($columntype === column::TYPE_BOOLEAN || empty($callbacks)) {
$decimalpoints = (int) ($columntype === column::TYPE_FLOAT);
return format_float((float) reset($values), $decimalpoints);
return format_float((float) $firstvalue, $decimalpoints);
}
return parent::format_value($value, $values, $callbacks, $columntype);

View File

@ -206,7 +206,7 @@ class user_profile_fields_test extends core_reportbuilder_testcase {
$this->assertEquals([
[
'c0_firstname' => 'Admin',
'c1_data' => 'No',
'c1_data' => '',
'c2_data' => 'Not set',
'c3_data' => '',
'c4_data' => '',