diff --git a/tag/classes/reportbuilder/local/entities/tag.php b/tag/classes/reportbuilder/local/entities/tag.php index ea93d2a46b6..ebc9395e5cf 100644 --- a/tag/classes/reportbuilder/local/entities/tag.php +++ b/tag/classes/reportbuilder/local/entities/tag.php @@ -171,8 +171,8 @@ class tag extends base { )) ->add_joins($this->get_joins()) ->set_type(column::TYPE_BOOLEAN) - ->add_fields("{$tagalias}.flag") - ->set_is_sortable(true) + ->add_field("CASE WHEN {$tagalias}.flag > 0 THEN 1 ELSE {$tagalias}.flag END", 'flag') + ->set_is_sortable(true, ["{$tagalias}.flag"]) ->add_callback([format::class, 'boolean_as_text']); // Time modified. @@ -224,7 +224,7 @@ class tag extends base { 'flagged', new lang_string('flagged', 'core_tag'), $this->get_entity_name(), - "{$tagalias}.flag" + "CASE WHEN {$tagalias}.flag > 0 THEN 1 ELSE {$tagalias}.flag END" )) ->add_joins($this->get_joins()); diff --git a/tag/tests/reportbuilder/datasource/tags_test.php b/tag/tests/reportbuilder/datasource/tags_test.php index 5aebcb762bb..2e0c6c94e2e 100644 --- a/tag/tests/reportbuilder/datasource/tags_test.php +++ b/tag/tests/reportbuilder/datasource/tags_test.php @@ -84,6 +84,7 @@ class tags_test extends core_reportbuilder_testcase { public function test_datasource_non_default_columns(): void { $this->resetAfterTest(); + $this->getDataGenerator()->create_tag(['name' => 'Horses', 'description' => 'Neigh', 'flag' => 2]); $course = $this->getDataGenerator()->create_course(['tags' => ['Horses']]); $coursecontext = context_course::instance($course->id); @@ -125,8 +126,8 @@ class tags_test extends core_reportbuilder_testcase { // Tag. $this->assertEquals('Horses', $courserow[4]); - $this->assertEmpty($courserow[5]); - $this->assertEquals('No', $courserow[6]); + $this->assertEquals('