From c0a52bc66c031bb9d3b7100b9da791f6d943c3b3 Mon Sep 17 00:00:00 2001 From: Mike Churchward Date: Fri, 30 Apr 2021 10:10:07 -0400 Subject: [PATCH] MDL-69863 tool_brickfield: Better instance name displayed in error list. --- .../brickfield/classes/local/tool/tool.php | 40 +++++++++++++++++++ .../classes/output/errors/renderer.php | 15 +++---- .../tool/brickfield/templates/errors.mustache | 28 ++++++------- 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/admin/tool/brickfield/classes/local/tool/tool.php b/admin/tool/brickfield/classes/local/tool/tool.php index 829871ee12c..2050262152d 100644 --- a/admin/tool/brickfield/classes/local/tool/tool.php +++ b/admin/tool/brickfield/classes/local/tool/tool.php @@ -264,6 +264,46 @@ abstract class tool { return($modulename); } + /** + * Get instance name for display + * @param string $component + * @param string $table + * @param int $cmid + * @param int $courseid + * @param int $categoryid + * @return string + */ + public static function get_instance_name(string $component, string $table, ?int $cmid, ?int $courseid, + ?int $categoryid): string { + global $DB; + + $instancename = ''; + if (empty($component)) { + return $instancename; + } + if ($component == 'core_course') { + if (($table == 'course_categories') && ($categoryid != 0) && ($categoryid != null)) { + $instancename = $DB->get_field($table, 'name', ['id' => $categoryid]); + return get_string('category') . ' - ' . $instancename; + } + if (($courseid == 0) || ($courseid == null)) { + return $instancename; + } + $thiscourse = get_fast_modinfo($courseid)->get_course(); + $instancename = $thiscourse->shortname; + } else if ($component == 'core_question') { + $instancename = get_string('questions', 'question'); + } else { + if (($cmid == 0) || ($cmid == null)) { + return $instancename; + } + $cm = get_fast_modinfo($courseid)->cms[$cmid]; + $instancename = $cm->name; + } + $instancename = static::get_module_label($component).' - '.$instancename; + return($instancename); + } + /** * Provide arguments required for the toplevel page, using any provided filter. * @param filter|null $filter diff --git a/admin/tool/brickfield/classes/output/errors/renderer.php b/admin/tool/brickfield/classes/output/errors/renderer.php index 3de4cf1c995..14ca3f6cf39 100644 --- a/admin/tool/brickfield/classes/output/errors/renderer.php +++ b/admin/tool/brickfield/classes/output/errors/renderer.php @@ -65,18 +65,19 @@ class renderer extends \tool_brickfield\output\renderer { $templatedata->tableheading1 = get_string('tbltarget', manager::PLUGINNAME); $templatedata->tableheading2 = get_string('tblcheck', manager::PLUGINNAME); - $templatedata->tableheading3 = get_string('tbledit', manager::PLUGINNAME); + $templatedata->tableheading3 = get_string('tblhtmlcode', manager::PLUGINNAME); $templatedata->tableheading4 = get_string('tblline', manager::PLUGINNAME); - $templatedata->tableheading5 = get_string('tblhtmlcode', manager::PLUGINNAME); + $templatedata->tableheading5 = get_string('tbledit', manager::PLUGINNAME); $templatedata->tabledata = []; foreach ($data->errordata as $err) { $row = new \stdClass(); - $row->activity = ucfirst(tool::get_module_label($err->component)); + $row->activity = ucfirst(tool::get_instance_name($err->component, $err->tablename, $err->cmid, + $err->courseid, $err->categoryid)); $row->check = $err->checkdesc; - $row->edit = $this->get_link($err); - $row->line = $err->errline; $row->html = $err->htmlcode; + $row->line = $err->errline; + $row->edit = $this->get_link($err, $row->activity); $templatedata->tabledata[] = $row; } @@ -90,10 +91,11 @@ class renderer extends \tool_brickfield\output\renderer { * Return a link to edit the appropriate content for the error. * * @param \stdClass $err + * @param string $titlestr * @return string * @throws \coding_exception */ - public function get_link(\stdClass $err): string { + public function get_link(\stdClass $err, string $titlestr): string { $out = ''; $areaclass = '\tool_brickfield\local\areas\\' . $err->component . '\base'; @@ -103,7 +105,6 @@ class renderer extends \tool_brickfield\output\renderer { $link = module_area_base::get_edit_url($err); } - $titlestr = ucfirst($err->component) . ' ' . ucfirst($err->shortname) . ' (ID ' . $err->resid . ')'; $title = get_string('errorlink', manager::PLUGINNAME, $titlestr); if (!isset($link)) { diff --git a/admin/tool/brickfield/templates/errors.mustache b/admin/tool/brickfield/templates/errors.mustache index 4b949832204..b31e6e4b938 100644 --- a/admin/tool/brickfield/templates/errors.mustache +++ b/admin/tool/brickfield/templates/errors.mustache @@ -25,23 +25,23 @@ "pagenavigation": " ", "tableheading1": "Activity", "tableheading2": "Check", - "tableheading3": "Edit", + "tableheading3": "Existing HTML code", "tableheading4": "Line", - "tableheading5": "Existing HTML code", + "tableheading5": "Edit", "tabledata": [ { "activity": "Book", "check": "Headings", - "edit": "Edit", + "html": "<h3></h3>", "line": 2, - "html": "<h3></h3>" + "edit": "Edit" }, { "activity": "Label", "check": "Headings", - "edit": "Edit", + "html": "<h3></h3>", "line": 4, - "html": "<h3></h3>" + "edit": "Edit" } ] } @@ -52,21 +52,21 @@ - - - + + + - + {{#tabledata}} - - - + + + - + {{/tabledata}}
{{tableheading1}}{{tableheading2}}{{tableheading3}}{{tableheading1}}{{tableheading2}}{{tableheading3}} {{tableheading4}}{{{tableheading5}}}{{{tableheading5}}}
{{activity}}{{check}}{{{edit}}}{{activity}}{{check}}{{html}} {{line}}{{html}}{{{edit}}}