mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-79397 reportbuilder: update reports to use auto-generated aliases.
We no longer need to be concerned about the manual setting of entity table aliases (e.g. to avoid duplication between entities, or for using a single entity multiple times), as it's handled transparently for us.
This commit is contained in:
parent
7143cf4cbc
commit
3dec3fb8ce
3 changed files with 17 additions and 22 deletions
|
@ -88,23 +88,21 @@ class blogs extends datasource {
|
|||
$this->add_entity($courseentity
|
||||
->add_join("LEFT JOIN {course} {$coursealias} ON {$coursealias}.id = {$postalias}.courseid"));
|
||||
|
||||
// Join the comment entity (ensure differing alias from that used by course entity).
|
||||
$commententity = (new comment())
|
||||
->set_table_alias('comments', 'bcmt');
|
||||
// Join the comment entity.
|
||||
$commententity = new comment();
|
||||
$commentalias = $commententity->get_table_alias('comments');
|
||||
$this->add_entity($commententity
|
||||
->add_join("LEFT JOIN {comments} bcmt ON bcmt.component = 'blog' AND bcmt.itemid = {$postalias}.id"));
|
||||
->add_join("LEFT JOIN {comments} {$commentalias} ON {$commentalias}.component = 'blog'
|
||||
AND {$commentalias}.itemid = {$postalias}.id"));
|
||||
|
||||
// Join the user entity to represent the comment author. Override table aliases to avoid clash with first instance.
|
||||
// Join the user entity to represent the comment author.
|
||||
$commenterentity = (new user())
|
||||
->set_entity_name('commenter')
|
||||
->set_entity_title(new lang_string('commenter', 'core_comment'))
|
||||
->set_table_aliases([
|
||||
'user' => 'cu',
|
||||
'context' => 'cuctx',
|
||||
]);
|
||||
->set_entity_title(new lang_string('commenter', 'core_comment'));
|
||||
$commenteralias = $commenterentity->get_table_alias('user');
|
||||
$this->add_entity($commenterentity
|
||||
->add_joins($commententity->get_joins())
|
||||
->add_join("LEFT JOIN {user} cu ON cu.id = bcmt.userid"));
|
||||
->add_join("LEFT JOIN {user} {$commenteralias} ON {$commenteralias}.id = {$commentalias}.userid"));
|
||||
|
||||
// Add report elements from each of the entities we added to the report.
|
||||
$this->add_all_from_entity($blogentity->get_entity_name());
|
||||
|
|
|
@ -60,13 +60,13 @@ class categories extends datasource {
|
|||
$this->add_entity($courseentity
|
||||
->add_join("LEFT JOIN {course} {$coursealias} ON {$coursealias}.category = {$categoryalias}.id"));
|
||||
|
||||
// Join cohort entity (amend alias to avoid clash with course entity, indicate context table join alias).
|
||||
// Join cohort entity (indicate context table join alias).
|
||||
$cohortentity = (new cohort())
|
||||
->set_table_alias('cohort', 'ch')
|
||||
->set_table_join_alias('context', $contextalias);
|
||||
$cohort = $cohortentity->get_table_alias('cohort');
|
||||
$this->add_entity($cohortentity
|
||||
->add_join($categoryentity->get_context_join())
|
||||
->add_join("LEFT JOIN {cohort} ch ON ch.contextid = {$contextalias}.id"));
|
||||
->add_join("LEFT JOIN {cohort} {$cohort} ON {$cohort}.contextid = {$contextalias}.id"));
|
||||
|
||||
// Join role entity.
|
||||
$roleentity = (new role())
|
||||
|
|
|
@ -68,17 +68,14 @@ class notes extends datasource {
|
|||
ON {$recipientalias}.id = {$postalias}.userid")
|
||||
);
|
||||
|
||||
// Join the user entity to represent the note author. Override all entity table aliases to avoid clash with first instance.
|
||||
// Join the user entity to represent the note author.
|
||||
$authorentity = (new user())
|
||||
->set_entity_name('author')
|
||||
->set_entity_title(new lang_string('author', 'core_notes'))
|
||||
->set_table_aliases([
|
||||
'user' => 'au',
|
||||
'context' => 'auctx',
|
||||
]);
|
||||
->set_entity_title(new lang_string('author', 'core_notes'));
|
||||
$authoralias = $authorentity->get_table_alias('user');
|
||||
$this->add_entity($authorentity->add_join("
|
||||
LEFT JOIN {user} au
|
||||
ON au.id = {$postalias}.usermodified")
|
||||
LEFT JOIN {user} {$authoralias}
|
||||
ON {$authoralias}.id = {$postalias}.usermodified")
|
||||
);
|
||||
|
||||
// Join the course entity for course notes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue