diff --git a/reportbuilder/classes/local/report/column.php b/reportbuilder/classes/local/report/column.php index 75f991f9c09..980f5cf4549 100644 --- a/reportbuilder/classes/local/report/column.php +++ b/reportbuilder/classes/local/report/column.php @@ -61,6 +61,9 @@ final class column { /** @var lang_string $columntitle Used as a title for the column in reports */ private $columntitle; + /** @var bool $hascustomcolumntitle Used to store if the column has been given a custom title */ + private $hascustomcolumntitle = false; + /** @var string $entityname Name of the entity this column belongs to */ private $entityname; @@ -151,6 +154,7 @@ final class column { */ public function set_title(?lang_string $title): self { $this->columntitle = $title; + $this->hascustomcolumntitle = true; return $this; } @@ -163,6 +167,15 @@ final class column { return $this->columntitle ? (string) $this->columntitle : ''; } + /** + * Check whether this column has been given a custom title + * + * @return bool + */ + public function has_custom_title(): bool { + return $this->hascustomcolumntitle; + } + /** * Get column entity name * diff --git a/reportbuilder/classes/local/systemreports/reports_list.php b/reportbuilder/classes/local/systemreports/reports_list.php index b026c962adc..1ad7cef1cd9 100644 --- a/reportbuilder/classes/local/systemreports/reports_list.php +++ b/reportbuilder/classes/local/systemreports/reports_list.php @@ -181,7 +181,8 @@ class reports_list extends system_report { ); // The user who modified the report. - $this->add_column_from_entity('user:fullname'); + $this->add_column_from_entity('user:fullname') + ->set_title(new lang_string('usermodified', 'reportbuilder')); // Initial sorting. $this->set_initial_sort_column('report:timecreated', SORT_DESC); diff --git a/reportbuilder/classes/table/system_report_table.php b/reportbuilder/classes/table/system_report_table.php index 0586da66118..a65e5798c50 100644 --- a/reportbuilder/classes/table/system_report_table.php +++ b/reportbuilder/classes/table/system_report_table.php @@ -101,8 +101,8 @@ class system_report_table extends base_report_table { $columnheaders[$column->get_column_alias()] = $column->get_title(); - // Specify whether column should behave as a user fullname column. - if (preg_match('/^user:fullname.*$/', $column->get_unique_identifier())) { + // Specify whether column should behave as a user fullname column unless the column has a custom title set. + if (preg_match('/^user:fullname.*$/', $column->get_unique_identifier()) && !$column->has_custom_title()) { $this->userfullnamecolumns[] = $column->get_column_alias(); } diff --git a/reportbuilder/tests/behat/customreports.feature b/reportbuilder/tests/behat/customreports.feature index 35495e4ac51..7770f3bd8df 100644 --- a/reportbuilder/tests/behat/customreports.feature +++ b/reportbuilder/tests/behat/customreports.feature @@ -33,8 +33,8 @@ Feature: Manage custom reports Then I should see "Email address" in the "[data-region='report-filters']" "css_element" And I navigate to "Reports > Report builder > Custom reports" in site administration And the following should exist in the "reportbuilder-table" table: - | Name | Report source | - | My report | Users | + | Name | Report source | Modified by | + | My report | Users | Admin User | Scenario: Create custom report without default setup Given I log in as "admin" diff --git a/reportbuilder/tests/local/report/column_test.php b/reportbuilder/tests/local/report/column_test.php index 99f7d117172..3cbe8d974e9 100644 --- a/reportbuilder/tests/local/report/column_test.php +++ b/reportbuilder/tests/local/report/column_test.php @@ -53,11 +53,13 @@ class column_test extends advanced_testcase { public function test_title(): void { $column = $this->create_column('test', new lang_string('show')); $this->assertEquals('Show', $column->get_title()); + $this->assertFalse($column->has_custom_title()); $this->assertEquals('Hide', $column ->set_title(new lang_string('hide')) ->get_title() ); + $this->assertTrue($column->has_custom_title()); // Column titles can also be empty. $this->assertEmpty($column