MDL-69863 tool_brickfield: Better instance name displayed in error list.

This commit is contained in:
Mike Churchward 2021-04-30 10:10:07 -04:00 committed by Eloy Lafuente (stronk7)
parent 7331bb1454
commit 498f75502a
3 changed files with 62 additions and 21 deletions

View file

@ -264,6 +264,46 @@ abstract class tool {
return($modulename); 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. * Provide arguments required for the toplevel page, using any provided filter.
* @param filter|null $filter * @param filter|null $filter

View file

@ -65,18 +65,19 @@ class renderer extends \tool_brickfield\output\renderer {
$templatedata->tableheading1 = get_string('tbltarget', manager::PLUGINNAME); $templatedata->tableheading1 = get_string('tbltarget', manager::PLUGINNAME);
$templatedata->tableheading2 = get_string('tblcheck', 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->tableheading4 = get_string('tblline', manager::PLUGINNAME);
$templatedata->tableheading5 = get_string('tblhtmlcode', manager::PLUGINNAME); $templatedata->tableheading5 = get_string('tbledit', manager::PLUGINNAME);
$templatedata->tabledata = []; $templatedata->tabledata = [];
foreach ($data->errordata as $err) { foreach ($data->errordata as $err) {
$row = new \stdClass(); $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->check = $err->checkdesc;
$row->edit = $this->get_link($err);
$row->line = $err->errline;
$row->html = $err->htmlcode; $row->html = $err->htmlcode;
$row->line = $err->errline;
$row->edit = $this->get_link($err, $row->activity);
$templatedata->tabledata[] = $row; $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. * Return a link to edit the appropriate content for the error.
* *
* @param \stdClass $err * @param \stdClass $err
* @param string $titlestr
* @return string * @return string
* @throws \coding_exception * @throws \coding_exception
*/ */
public function get_link(\stdClass $err): string { public function get_link(\stdClass $err, string $titlestr): string {
$out = ''; $out = '';
$areaclass = '\tool_brickfield\local\areas\\' . $err->component . '\base'; $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); $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); $title = get_string('errorlink', manager::PLUGINNAME, $titlestr);
if (!isset($link)) { if (!isset($link)) {

View file

@ -25,23 +25,23 @@
"pagenavigation": " ", "pagenavigation": " ",
"tableheading1": "Activity", "tableheading1": "Activity",
"tableheading2": "Check", "tableheading2": "Check",
"tableheading3": "Edit", "tableheading3": "Existing HTML code",
"tableheading4": "Line", "tableheading4": "Line",
"tableheading5": "Existing HTML code", "tableheading5": "Edit",
"tabledata": [ "tabledata": [
{ {
"activity": "Book", "activity": "Book",
"check": "Headings", "check": "Headings",
"edit": "<a href=\"link.com\">Edit</a>", "html": "&lt;h3&gt;&lt;/h3&gt;",
"line": 2, "line": 2,
"html": "&lt;h3&gt;&lt;/h3&gt;" "edit": "<a href=\"link.com\">Edit</a>"
}, },
{ {
"activity": "Label", "activity": "Label",
"check": "Headings", "check": "Headings",
"edit": "<a href=\"link.com\">Edit</a>", "html": "&lt;h3&gt;&lt;/h3&gt;",
"line": 4, "line": 4,
"html": "&lt;h3&gt;&lt;/h3&gt;" "edit": "<a href=\"link.com\">Edit</a>"
} }
] ]
} }
@ -52,21 +52,21 @@
<table class="generaltable"> <table class="generaltable">
<thead> <thead>
<tr> <tr>
<th class="header c0" style="width: 10%;" scope="col">{{tableheading1}}</th> <th class="header c0" style="width: 30%;" scope="col">{{tableheading1}}</th>
<th class="header c1" style="width: 20%;" scope="col">{{tableheading2}}</th> <th class="header c1" style="width: 30%;" scope="col">{{tableheading2}}</th>
<th class="header c2" style="width: 5%;" scope="col">{{tableheading3}}</th> <th class="header c2" style="width: 30%;" scope="col">{{tableheading3}}</th>
<th class="header c3" style="width: 5%;" scope="col">{{tableheading4}}</th> <th class="header c3" style="width: 5%;" scope="col">{{tableheading4}}</th>
<th class="header c4 lastcol" style="width: 60%;" scope="col">{{{tableheading5}}}</th> <th class="header c4 lastcol" style="width: 5%;" scope="col">{{{tableheading5}}}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{#tabledata}} {{#tabledata}}
<tr> <tr>
<td class="cell c0" style="width:10%;">{{activity}}</td> <td class="cell c0" style="width:30%;">{{activity}}</td>
<td class="cell c1" style="width:20%;">{{check}}</td> <td class="cell c1" style="width:30%;">{{check}}</td>
<td class="cell c2" style="width:5%;">{{{edit}}}</td> <td class="cell c2" style="width:30%;">{{html}}</td>
<td class="cell c3" style="width:5%;">{{line}}</td> <td class="cell c3" style="width:5%;">{{line}}</td>
<td class="cell c4" style="width:60%;">{{html}}</td> <td class="cell c4" style="width:5%;">{{{edit}}}</td>
</tr> </tr>
{{/tabledata}} {{/tabledata}}
</tbody> </tbody>