This commit is contained in:
Ilya Tregubov
2023-05-17 15:14:22 +08:00
4 changed files with 27 additions and 5 deletions
@@ -76,10 +76,11 @@ class blogs extends datasource {
->add_joins($blogentity->get_tag_joins()));
// Join the user entity to represent the blog author.
$userentity = new user();
$useralias = $userentity->get_table_alias('user');
$this->add_entity($userentity
->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$postalias}.userid"));
$authorentity = (new user())
->set_entity_title(new lang_string('author', 'core_blog'));
$authoralias = $authorentity->get_table_alias('user');
$this->add_entity($authorentity
->add_join("LEFT JOIN {user} {$authoralias} ON {$authoralias}.id = {$postalias}.userid"));
// Join the course entity for course blogs.
$courseentity = new course();
@@ -93,6 +94,18 @@ class blogs extends datasource {
$this->add_entity($commententity
->add_join("LEFT JOIN {comments} bcmt ON bcmt.component = 'blog' AND bcmt.itemid = {$postalias}.id"));
// Join the user entity to represent the comment author. Override table aliases to avoid clash with first instance.
$commenterentity = (new user())
->set_entity_name('commenter')
->set_entity_title(new lang_string('commenter', 'core_comment'))
->set_table_aliases([
'user' => 'cu',
'context' => 'cuctx',
]);
$this->add_entity($commenterentity
->add_joins($commententity->get_joins())
->add_join("LEFT JOIN {user} cu ON cu.id = bcmt.userid"));
// Add report elements from each of the entities we added to the report.
$this->add_all_from_entity($blogentity->get_entity_name());
@@ -105,13 +118,15 @@ class blogs extends datasource {
$this->add_filter($tagentity->get_filter('name'));
$this->add_condition($tagentity->get_condition('name'));
$this->add_all_from_entity($userentity->get_entity_name());
$this->add_all_from_entity($authorentity->get_entity_name());
$this->add_all_from_entity($courseentity->get_entity_name());
// Add specific comment entity elements.
$this->add_columns_from_entity($commententity->get_entity_name(), ['content', 'timecreated']);
$this->add_filter($commententity->get_filter('timecreated'));
$this->add_condition($commententity->get_filter('timecreated'));
$this->add_all_from_entity($commenterentity->get_entity_name());
}
/**
@@ -143,6 +143,9 @@ class blogs_test extends core_reportbuilder_testcase {
// Comment entity.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'comment:content']);
// Commenter entity.
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'commenter:fullname']);
$content = $this->get_custom_report_content($report->get('id'));
$this->assertCount(1, $content);
@@ -154,6 +157,7 @@ class blogs_test extends core_reportbuilder_testcase {
$tags,
$filesize,
$comment,
$commenter,
] = array_values($content[0]);
$this->assertStringContainsString('Horses', $body);
@@ -163,6 +167,7 @@ class blogs_test extends core_reportbuilder_testcase {
$this->assertEquals('horse', $tags);
$this->assertEquals("5\xc2\xa0bytes", $filesize);
$this->assertEquals(format_text('Cool'), $comment);
$this->assertEquals(fullname($user), $commenter);
}
/**
+1
View File
@@ -31,6 +31,7 @@ $string['associatewithmodule'] = 'Blog about {$a->modtype}: {$a->modname}';
$string['association'] = 'Association';
$string['associations'] = 'Associations';
$string['associationunviewable'] = 'This entry cannot be viewed by others until a course is associated with it or the \'Publish to\' field is changed';
$string['author'] = 'Author';
$string['autotags'] = 'Add these tags';
$string['autotags_help'] = 'Enter one or more local tags (separated by commas) that you want to automatically add to each blog entry copied from the external blog into your local blog.';
$string['backupblogshelp'] = 'If enabled then blogs will be included in SITE automated backups';
+1
View File
@@ -23,6 +23,7 @@
*/
$string['comment'] = 'Comment';
$string['commenter'] = 'Commenter';
$string['comments'] = 'Comments';
$string['commentsubcontext'] = 'Comments';
$string['privacy:metadata:comment'] = 'Stores comments of users.';