Skip to content

Commit

Permalink
Merge branch 'MDL-79536' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Nov 6, 2023
2 parents 8d7511b + 6b712f5 commit c53b560
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
30 changes: 20 additions & 10 deletions blog/classes/reportbuilder/local/entities/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use blog_entry_attachment;
use context_system;
use core_collator;
use lang_string;
use stdClass;
use core_reportbuilder\local\entities\base;
Expand Down Expand Up @@ -165,21 +166,25 @@ protected function get_all_columns(): array {
// Publish state.
$columns[] = (new column(
'publishstate',
new lang_string('publishto', 'core_blog'),
new lang_string('published', 'core_blog'),
$this->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_fields("{$postalias}.publishstate")
->add_field("{$postalias}.publishstate")
->set_is_sortable(true)
->add_callback(static function(?string $publishstate): string {
$states = [
'draft' => new lang_string('publishtonoone', 'core_blog'),
'draft' => new lang_string('publishtodraft', 'core_blog'),
'site' => new lang_string('publishtosite', 'core_blog'),
'public' => new lang_string('publishtoworld', 'core_blog'),
];

return (string) ($states[$publishstate] ?? $publishstate ?? '');
if ($publishstate === null || !array_key_exists($publishstate, $states)) {
return (string) $publishstate;
}

return (string) $states[$publishstate];
});

// Time created.
Expand Down Expand Up @@ -253,16 +258,21 @@ protected function get_all_filters(): array {
$filters[] = (new filter(
select::class,
'publishstate',
new lang_string('publishto', 'core_blog'),
new lang_string('published', 'core_blog'),
$this->get_entity_name(),
"{$postalias}.publishstate"
))
->add_joins($this->get_joins())
->set_options([
'draft' => new lang_string('publishtonoone', 'core_blog'),
'site' => new lang_string('publishtosite', 'core_blog'),
'public' => new lang_string('publishtoworld', 'core_blog'),
]);
->set_options_callback(static function(): array {
$states = [
'draft' => new lang_string('publishtodraft', 'core_blog'),
'site' => new lang_string('publishtosite', 'core_blog'),
'public' => new lang_string('publishtoworld', 'core_blog'),
];

core_collator::asort($states);
return $states;
});

// Time created.
$filters[] = (new filter(
Expand Down
2 changes: 1 addition & 1 deletion blog/tests/reportbuilder/datasource/blogs_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function test_datasource_non_default_columns(): void {

$this->assertStringContainsString('Horses', $body);
$this->assertStringContainsString('hello.txt', $attachment);
$this->assertEquals('Yourself (draft)', $publishstate);
$this->assertEquals('Draft', $publishstate);
$this->assertEquals(userdate($blog->lastmodified), $timemodified);
$this->assertEquals('horse', $tags);
$this->assertEquals("5\xc2\xa0bytes", $filesize);
Expand Down
2 changes: 2 additions & 0 deletions lang/en/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
$string['privacy:metadata:post:usermodified'] = 'The user who last modified the entry';
$string['privacy:path:blogassociations'] = 'Associated blog posts';
$string['privacy:unknown'] = 'Unknown';
$string['published'] = 'Published';
$string['publishto'] = 'Publish to';
$string['publishto_help'] = 'There are 3 options:
Expand All @@ -162,6 +163,7 @@
$string['publishtocourse'] = 'Users sharing a course with you';
$string['publishtocourseassoc'] = 'Members of the associated course';
$string['publishtocourseassocparam'] = 'Members of {$a}';
$string['publishtodraft'] = 'Draft';
$string['publishtogroup'] = 'Users sharing a group with you';
$string['publishtogroupassoc'] = 'Your group members in the associated course';
$string['publishtogroupassocparam'] = 'Your group members in {$a}';
Expand Down

0 comments on commit c53b560

Please sign in to comment.