Skip to content

Commit

Permalink
MDL-77062 reportbuilder: Add filters/conditions for completion entity
Browse files Browse the repository at this point in the history
This commit will add missing fields as Time enrolled/started/reaggregated
in the filter/condition area for the completion entity when creating a course participants
as a report source in the Report Builder.
  • Loading branch information
guillogo committed Jan 31, 2023
1 parent 880462a commit 43c64bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions course/classes/reportbuilder/local/entities/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 22 additions & 0 deletions course/tests/reportbuilder/datasource/participants_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
];
}

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 43c64bc

Please sign in to comment.