diff --git a/course/classes/reportbuilder/local/entities/completion.php b/course/classes/reportbuilder/local/entities/completion.php index efcad9248bbe4..78f0030527522 100644 --- a/course/classes/reportbuilder/local/entities/completion.php +++ b/course/classes/reportbuilder/local/entities/completion.php @@ -275,6 +275,45 @@ protected function get_all_filters(): array { date::DATE_CURRENT, ]); + // Time enrolled/started filter and condition. + $fields = ['timeenrolled', 'timestarted']; + foreach ($fields as $field) { + $filters[] = (new filter( + date::class, + $field, + new lang_string($field, 'enrol'), + $this->get_entity_name(), + "{$coursecompletion}.{$field}" + )) + ->add_joins($this->get_joins()) + ->set_limited_operators([ + date::DATE_ANY, + date::DATE_NOT_EMPTY, + date::DATE_EMPTY, + date::DATE_RANGE, + date::DATE_LAST, + date::DATE_CURRENT, + ]); + } + + // Time reaggregated filter and condition. + $filters[] = (new filter( + date::class, + 'reaggregate', + new lang_string('timereaggregated', 'enrol'), + $this->get_entity_name(), + "{$coursecompletion}.reaggregate" + )) + ->add_joins($this->get_joins()) + ->set_limited_operators([ + date::DATE_ANY, + date::DATE_NOT_EMPTY, + date::DATE_EMPTY, + date::DATE_RANGE, + date::DATE_LAST, + date::DATE_CURRENT, + ]); + return $filters; } } diff --git a/course/tests/reportbuilder/datasource/participants_test.php b/course/tests/reportbuilder/datasource/participants_test.php index 25025ae019113..2136ac2cfc94b 100644 --- a/course/tests/reportbuilder/datasource/participants_test.php +++ b/course/tests/reportbuilder/datasource/participants_test.php @@ -210,6 +210,27 @@ public function filters_data_provider(): array { ], 'Lionel' ], + [ + 'completion:timeenrolled', + [ + 'completion:timeenrolled_operator' => date::DATE_NOT_EMPTY, + ], + 'Lionel' + ], + [ + 'completion:timestarted', + [ + 'completion:timestarted_operator' => date::DATE_NOT_EMPTY, + ], + 'Lionel' + ], + [ + 'completion:reaggregate', + [ + 'completion:reaggregate_operator' => date::DATE_NOT_EMPTY, + ], + 'Lionel' + ], ]; } @@ -254,6 +275,7 @@ public function test_report_filters(string $filter, array $filtervalues, string // Mark course as completed for the user. $ccompletion = new completion_completion(array('course' => $course->id, 'userid' => $user1->id)); $ccompletion->mark_enrolled($timestart); + $ccompletion->mark_inprogress($timestart); $ccompletion->mark_complete($timecompleted); // Set some last access value for the user in the course.