Merge branch 'MDL-75358-400' of https://github.com/marinaglancy/moodle into MOODLE_400_STABLE
This commit is contained in:
@@ -73,6 +73,9 @@ class avg extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
if (reset($values) === null) {
|
||||
return null;
|
||||
}
|
||||
return format_float((float) reset($values), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ class groupconcat extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
$firstvalue = reset($values);
|
||||
if ($firstvalue === null) {
|
||||
return '';
|
||||
}
|
||||
$formattedvalues = [];
|
||||
|
||||
// Store original names of all values that would be present without aggregation.
|
||||
@@ -117,7 +121,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.
|
||||
|
||||
@@ -72,6 +72,9 @@ class percent extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
if (reset($values) === null) {
|
||||
return '';
|
||||
}
|
||||
return format::percent(reset($values));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,9 @@ class sum extends base {
|
||||
* @return mixed
|
||||
*/
|
||||
public static function format_value($value, array $values, array $callbacks) {
|
||||
if (reset($values) === null) {
|
||||
return '';
|
||||
}
|
||||
return (int) reset($values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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' => '',
|
||||
|
||||
Reference in New Issue
Block a user