mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-76154 blog: add files/attachments to custom report source.
This commit is contained in:
parent
5019abfdd6
commit
224b3ab51f
@ -22,6 +22,7 @@ use lang_string;
|
||||
use core_reportbuilder\datasource;
|
||||
use core_reportbuilder\local\entities\{course, user};
|
||||
use core_blog\reportbuilder\local\entities\blog;
|
||||
use core_files\reportbuilder\local\entities\file;
|
||||
use core_tag\reportbuilder\local\entities\tag;
|
||||
|
||||
/**
|
||||
@ -54,6 +55,18 @@ class blogs extends datasource {
|
||||
|
||||
$this->add_entity($blogentity);
|
||||
|
||||
// Join the files entity.
|
||||
$fileentity = (new file())
|
||||
->set_entity_title(new lang_string('blogattachment', 'core_blog'));
|
||||
$filesalias = $fileentity->get_table_alias('files');
|
||||
$this->add_entity($fileentity
|
||||
->add_join("LEFT JOIN {files} {$filesalias}
|
||||
ON {$filesalias}.contextid = " . SYSCONTEXTID . "
|
||||
AND {$filesalias}.component = 'blog'
|
||||
AND {$filesalias}.filearea = 'attachment'
|
||||
AND {$filesalias}.itemid = {$postalias}.id
|
||||
AND {$filesalias}.filename != '.'"));
|
||||
|
||||
// Join the tag entity.
|
||||
$tagentity = (new tag())
|
||||
->set_entity_title(new lang_string('blogtags', 'core_blog'))
|
||||
@ -76,7 +89,11 @@ class blogs extends datasource {
|
||||
// Add report elements from each of the entities we added to the report.
|
||||
$this->add_all_from_entity($blogentity->get_entity_name());
|
||||
|
||||
// Add specific tag entity elements.
|
||||
// Add specific file/tag entity elements.
|
||||
$this->add_columns_from_entity($fileentity->get_entity_name(), ['name', 'size', 'type', 'timecreated']);
|
||||
$this->add_filters_from_entity($fileentity->get_entity_name(), ['name', 'size', 'timecreated']);
|
||||
$this->add_conditions_from_entity($fileentity->get_entity_name(), ['name', 'size', 'timecreated']);
|
||||
|
||||
$this->add_columns_from_entity($tagentity->get_entity_name(), ['name', 'namewithlink']);
|
||||
$this->add_filter($tagentity->get_filter('name'));
|
||||
$this->add_condition($tagentity->get_condition('name'));
|
||||
|
@ -124,15 +124,27 @@ class blogs_test extends core_reportbuilder_testcase {
|
||||
// Tag entity (course/user presence already checked by default columns).
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'tag:name']);
|
||||
|
||||
// File entity.
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'file:size']);
|
||||
|
||||
$content = $this->get_custom_report_content($report->get('id'));
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
[$body, $attachment, $publishstate, $timemodified, $tags] = array_values($content[0]);
|
||||
[
|
||||
$body,
|
||||
$attachment,
|
||||
$publishstate,
|
||||
$timemodified,
|
||||
$tags,
|
||||
$filesize,
|
||||
] = array_values($content[0]);
|
||||
|
||||
$this->assertStringContainsString('Horses', $body);
|
||||
$this->assertStringContainsString('hello.txt', $attachment);
|
||||
$this->assertEquals('Yourself (draft)', $publishstate);
|
||||
$this->assertEquals(userdate($blog->lastmodified), $timemodified);
|
||||
$this->assertEquals('horse', $tags);
|
||||
$this->assertEquals("5\xc2\xa0bytes", $filesize);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,7 @@ $string['blogaboutthis'] = 'Blog about this {$a->type}';
|
||||
$string['blogaboutthiscourse'] = 'Add an entry about this course';
|
||||
$string['blogaboutthismodule'] = 'Add an entry about this {$a}';
|
||||
$string['blogadministration'] = 'Blog administration';
|
||||
$string['blogattachment'] = 'Blog attachment';
|
||||
$string['blogdeleteconfirm'] = 'Delete the blog entry \'{$a}\'?';
|
||||
$string['blogdisable'] = 'Blogging is disabled!';
|
||||
$string['blogentries'] = 'Blog entries';
|
||||
|
Loading…
x
Reference in New Issue
Block a user