diff --git a/blog/classes/reportbuilder/datasource/blogs.php b/blog/classes/reportbuilder/datasource/blogs.php index e6dac6a5858..ee89075d86b 100644 --- a/blog/classes/reportbuilder/datasource/blogs.php +++ b/blog/classes/reportbuilder/datasource/blogs.php @@ -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()); diff --git a/course/classes/reportbuilder/datasource/categories.php b/course/classes/reportbuilder/datasource/categories.php index 6957d759de9..4189c6cf035 100644 --- a/course/classes/reportbuilder/datasource/categories.php +++ b/course/classes/reportbuilder/datasource/categories.php @@ -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()) diff --git a/notes/classes/reportbuilder/datasource/notes.php b/notes/classes/reportbuilder/datasource/notes.php index c209b9cc2c1..ff1b68f60fa 100644 --- a/notes/classes/reportbuilder/datasource/notes.php +++ b/notes/classes/reportbuilder/datasource/notes.php @@ -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.