MDL-73001 reportbuilder: Allow to set custom title to fullname columns

This commit is contained in:
David Matamoros
2021-11-08 13:54:41 +01:00
parent d135a1200a
commit aaa041a9bd
5 changed files with 21 additions and 5 deletions
@@ -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
*
@@ -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);
@@ -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();
}
@@ -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"
@@ -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