mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
Merge branch 'MDL-82202' of https://github.com/paulholden/moodle
This commit is contained in:
commit
c53b23e47e
@ -96,15 +96,13 @@ class access extends base {
|
||||
->add_field("{$tablealias}.timeaccess")
|
||||
->add_field("{$user}.id", 'userid')
|
||||
->set_is_sortable(true)
|
||||
->add_callback([format::class, 'userdate'])
|
||||
->add_callback(static function(string $value, stdClass $row): string {
|
||||
if (!$row->userid) {
|
||||
->add_callback(static function(?int $value, stdClass $row, $arguments, ?string $aggregation): string {
|
||||
if ($row->userid === null && $aggregation === null) {
|
||||
return '';
|
||||
}
|
||||
if ($value === '') {
|
||||
} else if ($value === null) {
|
||||
return get_string('never');
|
||||
}
|
||||
return $value;
|
||||
return format::userdate($value, $row);
|
||||
});
|
||||
|
||||
return $columns;
|
||||
|
@ -241,6 +241,43 @@ final class participants_test extends core_reportbuilder_testcase {
|
||||
], array_values($content[0]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test creating course report, with aggregated last access date (minimum and maximum)
|
||||
*/
|
||||
public function test_course_last_access_aggregation(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$userone = $this->getDataGenerator()->create_and_enrol($course);
|
||||
$useronelastaccess = $this->getDataGenerator()->create_user_course_lastaccess($userone, $course, 1622502000);
|
||||
|
||||
$usertwo = $this->getDataGenerator()->create_and_enrol($course);
|
||||
$usertwolastaccess = $this->getDataGenerator()->create_user_course_lastaccess($usertwo, $course, 1622847600);
|
||||
|
||||
/** @var core_reportbuilder_generator $generator */
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
||||
|
||||
$report = $generator->create_report(['name' => 'Courses', 'source' => participants::class, 'default' => 0]);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'course:fullname']);
|
||||
$column = $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'access:timeaccess']);
|
||||
|
||||
// Course aggregated with "Minimum" last access.
|
||||
$column->set('aggregation', 'min')->update();
|
||||
$content = $this->get_custom_report_content($report->get('id'));
|
||||
$this->assertEquals([
|
||||
[$course->fullname, userdate($useronelastaccess->timeaccess)],
|
||||
], array_map('array_values', $content));
|
||||
|
||||
// Course aggregated with "Maximum" last access.
|
||||
$column->set('aggregation', 'max')->update();
|
||||
$content = $this->get_custom_report_content($report->get('id'));
|
||||
$this->assertEquals([
|
||||
[$course->fullname, userdate($usertwolastaccess->timeaccess)],
|
||||
], array_map('array_values', $content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for {@see test_datasource_filters}
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user