diff --git a/reportbuilder/classes/external/custom_report_exporter.php b/reportbuilder/classes/external/custom_report_exporter.php index 00de414418c..9fb6f60e8ad 100644 --- a/reportbuilder/classes/external/custom_report_exporter.php +++ b/reportbuilder/classes/external/custom_report_exporter.php @@ -93,6 +93,13 @@ class custom_report_exporter extends persistent_exporter { 'filtersapplied' => ['type' => PARAM_INT], 'filterspresent' => ['type' => PARAM_BOOL], 'filtersform' => ['type' => PARAM_RAW], + 'attributes' => [ + 'type' => [ + 'name' => ['type' => PARAM_TEXT], + 'value' => ['type' => PARAM_TEXT] + ], + 'multiple' => true, + ], 'editmode' => ['type' => PARAM_BOOL], 'sidebarmenucards' => [ 'type' => custom_report_column_cards_exporter::read_properties_definition(), @@ -130,6 +137,7 @@ class custom_report_exporter extends persistent_exporter { $filterspresent = false; $filtersform = ''; + $attributes = []; if ($this->editmode) { $table = custom_report_table::create($this->persistent->get('id')); @@ -147,6 +155,10 @@ class custom_report_exporter extends persistent_exporter { if ($filterspresent) { $filtersform = $this->generate_filters_form()->render(); } + // Get the report attributes. + $attributes = array_map(static function($key, $value): array { + return ['name' => $key, 'value' => $value]; + }, array_keys($report->get_attributes()), $report->get_attributes()); } // If we are editing we need all this information for the template. @@ -173,6 +185,7 @@ class custom_report_exporter extends persistent_exporter { 'filtersapplied' => $report->get_applied_filter_count(), 'filterspresent' => $filterspresent, 'filtersform' => $filtersform, + 'attributes' => $attributes, 'editmode' => $this->editmode, 'javascript' => '', ] + $editordata; diff --git a/reportbuilder/classes/external/system_report_exporter.php b/reportbuilder/classes/external/system_report_exporter.php index bc7fd29ed60..cabfa2a5457 100644 --- a/reportbuilder/classes/external/system_report_exporter.php +++ b/reportbuilder/classes/external/system_report_exporter.php @@ -70,6 +70,13 @@ class system_report_exporter extends persistent_exporter { 'filterspresent' => ['type' => PARAM_BOOL], 'filtersapplied' => ['type' => PARAM_INT], 'filtersform' => ['type' => PARAM_RAW], + 'attributes' => [ + 'type' => [ + 'name' => ['type' => PARAM_TEXT], + 'value' => ['type' => PARAM_TEXT] + ], + 'multiple' => true, + ], ]; } @@ -109,12 +116,18 @@ class system_report_exporter extends persistent_exporter { $filtersform->set_data_for_dynamic_submission(); } + // Get the report attributes. + $attributes = array_map(static function($key, $value): array { + return ['name' => $key, 'value' => $value]; + }, array_keys($source->get_attributes()), $source->get_attributes()); + return [ 'table' => $output->render($table), 'parameters' => $parameters, 'filterspresent' => $filterspresent, 'filtersapplied' => $source->get_applied_filter_count(), 'filtersform' => $filterspresent ? $filtersform->render() : '', + 'attributes' => $attributes, ]; } } diff --git a/reportbuilder/classes/local/report/base.php b/reportbuilder/classes/local/report/base.php index 5abe25d932f..c9c19922d40 100644 --- a/reportbuilder/classes/local/report/base.php +++ b/reportbuilder/classes/local/report/base.php @@ -87,6 +87,9 @@ abstract class base { /** @var int Default paging size */ private $defaultperpage = self::DEFAULT_PAGESIZE; + /** @var array $attributes */ + private $attributes = []; + /** * Base report constructor * @@ -744,4 +747,24 @@ abstract class base { public function get_default_per_page(): int { return $this->defaultperpage; } + + /** + * Add report attributes (data-, class, etc.) that will be included in HTML when report is displayed + * + * @param array $attributes + * @return self + */ + public function add_attributes(array $attributes): self { + $this->attributes = $attributes + $this->attributes; + return $this; + } + + /** + * Returns the report HTML attributes + * + * @return array + */ + public function get_attributes(): array { + return $this->attributes; + } } diff --git a/reportbuilder/templates/local/dynamictabs/editor.mustache b/reportbuilder/templates/local/dynamictabs/editor.mustache index 92f0d18e1ba..8f04f4d30eb 100644 --- a/reportbuilder/templates/local/dynamictabs/editor.mustache +++ b/reportbuilder/templates/local/dynamictabs/editor.mustache @@ -25,6 +25,10 @@ "type": 1, "table": "table", "editmode": true, + "attributes": [{ + "name": "data-custom", + "value": "1" + }], "sidebarmenucards": [{ "menucards": [{ "name": "General", @@ -93,7 +97,8 @@ data-report-id="{{id}}" data-report-type="{{type}}" data-parameter="[]" - {{#editmode}}data-editing{{/editmode}}> + {{#editmode}}data-editing{{/editmode}} + {{#attributes}}{{name}}="{{value}}" {{/attributes}}>
{{#editmode}} {{! Menu sidebar }} diff --git a/reportbuilder/templates/report.mustache b/reportbuilder/templates/report.mustache index 8912ccfebcc..ff28539a42f 100644 --- a/reportbuilder/templates/report.mustache +++ b/reportbuilder/templates/report.mustache @@ -25,6 +25,10 @@ "contextid": 1, "type": 1, "parameters": [], + "attributes": [{ + "name": "data-custom", + "value": "1" + }], "table": "table", "filterspresent": true, "filtersform": "form" @@ -34,7 +38,8 @@ data-region="core_reportbuilder/report" data-report-id="{{id}}" data-report-type="{{type}}" - data-parameter="{{parameters}}"> + data-parameter="{{parameters}}" + {{#attributes}}{{name}}="{{value}}" {{/attributes}}>
{{#filterspresent}}