mirror of
https://github.com/moodle/moodle.git
synced 2025-04-24 18:04:43 +02:00
MDL-76889 competency: add cohort data to competencies report source.
This commit is contained in:
parent
fd18c5014e
commit
8298abfbb1
competency
@ -19,10 +19,12 @@ declare(strict_types=1);
|
||||
namespace core_competency\reportbuilder\datasource;
|
||||
|
||||
use core\reportbuilder\local\entities\context;
|
||||
use core_cohort\reportbuilder\local\entities\cohort;
|
||||
use core_competency\reportbuilder\local\entities\{competency, framework, usercompetency};
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\local\entities\user;
|
||||
use core_reportbuilder\local\filters\boolean_select;
|
||||
use core_reportbuilder\local\helpers\database;
|
||||
|
||||
/**
|
||||
* Competencies datasource
|
||||
@ -88,8 +90,33 @@ class competencies extends datasource {
|
||||
->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$usercompetencyalias}.userid")
|
||||
);
|
||||
|
||||
// Join cohort entity.
|
||||
$cohortentity = new cohort();
|
||||
$cohortalias = $cohortentity->get_table_alias('cohort');
|
||||
$cohortmemberalias = database::generate_alias();
|
||||
$this->add_entity($cohortentity
|
||||
->add_joins($userentity->get_joins())
|
||||
->add_joins([
|
||||
"LEFT JOIN {cohort_members} {$cohortmemberalias} ON {$cohortmemberalias}.userid = {$useralias}.id",
|
||||
"LEFT JOIN {cohort} {$cohortalias} ON {$cohortalias}.id = {$cohortmemberalias}.cohortid",
|
||||
])
|
||||
);
|
||||
|
||||
// Add report elements from each of the entities we added to the report.
|
||||
$this->add_all_from_entities();
|
||||
$this->add_all_from_entities([
|
||||
$contextentity->get_entity_name(),
|
||||
$frameworkentity->get_entity_name(),
|
||||
$competencyentity->get_entity_name(),
|
||||
$usercompetencyentity->get_entity_name(),
|
||||
$userentity->get_entity_name(),
|
||||
]);
|
||||
|
||||
$this->add_all_from_entity(
|
||||
$cohortentity->get_entity_name(),
|
||||
['name', 'idnumber', 'description', 'customfield*'],
|
||||
['cohortselect', 'name', 'idnumber', 'customfield*'],
|
||||
['cohortselect', 'name', 'idnumber', 'customfield*'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,6 +90,9 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
|
||||
cohort_add_member($cohort->id, $user->id);
|
||||
|
||||
$scale = $this->getDataGenerator()->create_scale(['name' => 'My scale', 'scale' => 'A,B,C,D']);
|
||||
|
||||
/** @var core_competency_generator $generator */
|
||||
@ -125,6 +128,9 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'usercompetency:status']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'usercompetency:rating']);
|
||||
|
||||
// Cohort.
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']);
|
||||
|
||||
$content = $this->get_custom_report_content($report->get('id'));
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
@ -140,6 +146,7 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
$competencytimemodified,
|
||||
$usercompetencystatus,
|
||||
$usercompetencyrating,
|
||||
$cohortname,
|
||||
] = array_values($content[0]);
|
||||
|
||||
$this->assertEquals('So cool', $frameworkdescription);
|
||||
@ -153,6 +160,7 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
$this->assertNotEmpty($competencytimemodified);
|
||||
$this->assertEquals('Idle', $usercompetencystatus);
|
||||
$this->assertEquals('C', $usercompetencyrating);
|
||||
$this->assertEquals('My cohort', $cohortname);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,6 +277,16 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
'user:username_operator' => text::IS_NOT_EQUAL_TO,
|
||||
'user:username_value' => 'testuser',
|
||||
], false],
|
||||
|
||||
// Cohort.
|
||||
'Cohort name' => ['cohort:name', [
|
||||
'cohort:name_operator' => text::IS_EQUAL_TO,
|
||||
'cohort:name_value' => 'My cohort',
|
||||
], true],
|
||||
'Cohort name (no match)' => ['cohort:name', [
|
||||
'cohort:name_operator' => text::IS_EQUAL_TO,
|
||||
'cohort:name_value' => 'Another cohort',
|
||||
], false],
|
||||
];
|
||||
}
|
||||
|
||||
@ -289,7 +307,10 @@ final class competencies_test extends core_reportbuilder_testcase {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$user = $this->getDataGenerator()->create_user(['username' => 'testuser']);
|
||||
$scale = $this->getDataGenerator()->create_scale(['name' => 'My scale', 'scale' => 'A,B,C,D']);
|
||||
$cohort = $this->getDataGenerator()->create_cohort(['name' => 'My cohort']);
|
||||
cohort_add_member($cohort->id, $user->id);
|
||||
|
||||
$scale = $this->getDataGenerator()->create_scale([]);
|
||||
|
||||
/** @var core_competency_generator $generator */
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_competency');
|
||||
|
Loading…
x
Reference in New Issue
Block a user