Skip to content

Commit

Permalink
MDL-80342 reportbuilder: use new cohort filter in related reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Feb 21, 2024
1 parent 7f34237 commit 958090e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion badges/classes/reportbuilder/datasource/users.php
Expand Up @@ -105,7 +105,7 @@ protected function initialise(): void {
$this->add_all_from_entity($tagentity->get_entity_name(), ['name', 'namewithlink'], ['name'], ['name']);
$this->add_all_from_entity($courseentity->get_entity_name());
$this->add_all_from_entity($cohortentity->get_entity_name(), ['name', 'idnumber', 'description', 'customfield*'],
['name', 'idnumber', 'customfield*'], ['name', 'idnumber', 'customfield*']);
['cohortselect', 'name', 'idnumber', 'customfield*'], ['cohortselect', 'name', 'idnumber', 'customfield*']);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions cohort/classes/reportbuilder/local/entities/cohort.php
Expand Up @@ -24,6 +24,7 @@
use stdClass;
use core_reportbuilder\local\entities\base;
use core_reportbuilder\local\filters\boolean_select;
use core_reportbuilder\local\filters\cohort as cohort_filter;
use core_reportbuilder\local\filters\date;
use core_reportbuilder\local\filters\select;
use core_reportbuilder\local\filters\text;
Expand Down Expand Up @@ -260,6 +261,16 @@ protected function get_all_filters(): array {

$tablealias = $this->get_table_alias('cohort');

// Cohort select filter.
$filters[] = (new filter(
cohort_filter::class,
'cohortselect',
new lang_string('selectcohort', 'core_cohort'),
$this->get_entity_name(),
"{$tablealias}.id"
))
->add_joins($this->get_joins());

// Context filter.
$filters[] = (new filter(
select::class,
Expand Down
3 changes: 3 additions & 0 deletions cohort/tests/reportbuilder/datasource/cohorts_test.php
Expand Up @@ -145,6 +145,9 @@ public function test_datasource_non_default_columns(): void {
public function datasource_filters_provider(): array {
return [
// Cohort.
'Filter cohort' => ['cohort:cohortselect', [
'cohort:cohortselect_values' => [-1],
], false],
'Filter context' => ['cohort:context', [
'cohort:context_operator' => select::EQUAL_TO,
'cohort:context_value' => context_system::instance()->id,
Expand Down
1 change: 1 addition & 0 deletions lang/en/cohort.php
Expand Up @@ -78,6 +78,7 @@
$string['privacy:metadata:cohort_members:timeadded'] = 'The timestamp indicating when the user was added to the cohort';
$string['privacy:metadata:cohort_members:userid'] = 'The ID of the user which is associated to the cohort';
$string['removeuserwarning'] = 'Removing users from a cohort may result in unenrolling of users from multiple courses which includes deleting of user settings, grades, group membership and other user information from affected courses.';
$string['selectcohort'] = 'Select cohort';
$string['selectfromcohort'] = 'Select members from cohort';
$string['systemcohorts'] = 'System cohorts';
$string['unknowncohort'] = 'Unknown cohort ({$a})!';
Expand Down
2 changes: 1 addition & 1 deletion user/classes/reportbuilder/datasource/users.php
Expand Up @@ -81,7 +81,7 @@ protected function initialise(): void {
$this->add_all_from_entity($userentity->get_entity_name());
$this->add_all_from_entity($tagentity->get_entity_name(), ['name', 'namewithlink'], ['name'], ['name']);
$this->add_all_from_entity($cohortentity->get_entity_name(), ['name', 'idnumber', 'description', 'customfield*'],
['name', 'idnumber', 'customfield*'], ['name', 'idnumber', 'customfield*']);
['cohortselect', 'name', 'idnumber', 'customfield*'], ['cohortselect', 'name', 'idnumber', 'customfield*']);
}

/**
Expand Down

0 comments on commit 958090e

Please sign in to comment.