1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace tool_brickfield\output\errors;
|
|
|
18 |
|
|
|
19 |
use tool_brickfield\accessibility;
|
|
|
20 |
use tool_brickfield\local\areas\module_area_base;
|
|
|
21 |
use tool_brickfield\local\tool\filter;
|
|
|
22 |
use tool_brickfield\local\tool\tool;
|
|
|
23 |
use tool_brickfield\manager;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* tool_brickfield/errors renderer
|
|
|
27 |
*
|
|
|
28 |
* @package tool_brickfield
|
|
|
29 |
* @copyright 2020 onward: Brickfield Education Labs, https://www.brickfield.ie
|
|
|
30 |
* @author Mike Churchward
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class renderer extends \tool_brickfield\output\renderer {
|
|
|
34 |
/**
|
|
|
35 |
* Render the page containing the errors tool.
|
|
|
36 |
*
|
|
|
37 |
* @param \stdClass $data Report data.
|
|
|
38 |
* @param filter $filter Display filters.
|
|
|
39 |
* @return String HTML showing charts.
|
|
|
40 |
* @throws \coding_exception
|
|
|
41 |
* @throws \dml_exception
|
|
|
42 |
* @throws \moodle_exception
|
|
|
43 |
*/
|
|
|
44 |
public function display(\stdClass $data, filter $filter): string {
|
|
|
45 |
$templatedata = new \stdClass();
|
|
|
46 |
|
|
|
47 |
// Need a URL for the paging bar.
|
|
|
48 |
$pageurl = new \moodle_url(
|
|
|
49 |
accessibility::get_plugin_url(),
|
|
|
50 |
[
|
|
|
51 |
'courseid' => $filter->courseid,
|
|
|
52 |
'categoryid' => $filter->categoryid,
|
|
|
53 |
'tab' => $filter->tab,
|
|
|
54 |
'perpage' => $filter->perpage,
|
|
|
55 |
]
|
|
|
56 |
);
|
|
|
57 |
|
|
|
58 |
// Set up a table of data for the template.
|
|
|
59 |
$templatedata->pagetitle = accessibility::get_title($filter, $data->countdata);
|
|
|
60 |
|
|
|
61 |
if (count($data->errordata) == 0) {
|
|
|
62 |
$templatedata->noerrorsfound = get_string('noerrorsfound', manager::PLUGINNAME);
|
|
|
63 |
return $this->render_from_template(manager::PLUGINNAME . '/norecords', $templatedata);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
$templatedata->tableheading1 = get_string('tbltarget', manager::PLUGINNAME);
|
|
|
67 |
$templatedata->tableheading2 = get_string('tblcheck', manager::PLUGINNAME);
|
|
|
68 |
$templatedata->tableheading3 = get_string('tblhtmlcode', manager::PLUGINNAME);
|
|
|
69 |
$templatedata->tableheading4 = get_string('tblline', manager::PLUGINNAME);
|
|
|
70 |
$templatedata->tableheading5 = get_string('tbledit', manager::PLUGINNAME);
|
|
|
71 |
|
|
|
72 |
$templatedata->tabledata = [];
|
|
|
73 |
foreach ($data->errordata as $err) {
|
|
|
74 |
$row = new \stdClass();
|
|
|
75 |
$row->activity = ucfirst(tool::get_instance_name($err->component, $err->tablename, $err->cmid,
|
|
|
76 |
$err->courseid, $err->categoryid));
|
|
|
77 |
$row->check = $err->checkdesc;
|
|
|
78 |
$row->html = $err->htmlcode;
|
|
|
79 |
$row->line = $err->errline;
|
|
|
80 |
$row->edit = $this->get_link($err, $row->activity);
|
|
|
81 |
$templatedata->tabledata[] = $row;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$bar = new \paging_bar($data->errortotal, $filter->page, $filter->perpage, $pageurl->out());
|
|
|
85 |
$templatedata->pagenavigation = $this->render($bar);
|
|
|
86 |
|
|
|
87 |
return $this->render_from_template(manager::PLUGINNAME . '/errors', $templatedata);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Return a link to edit the appropriate content for the error.
|
|
|
92 |
*
|
|
|
93 |
* @param \stdClass $err
|
|
|
94 |
* @param string $titlestr
|
|
|
95 |
* @return string
|
|
|
96 |
* @throws \coding_exception
|
|
|
97 |
*/
|
|
|
98 |
public function get_link(\stdClass $err, string $titlestr): string {
|
|
|
99 |
$out = '';
|
|
|
100 |
|
|
|
101 |
$areaclass = '\tool_brickfield\local\areas\\' . $err->component . '\base';
|
|
|
102 |
if (class_exists($areaclass)) {
|
|
|
103 |
$link = $areaclass::get_edit_url($err);
|
|
|
104 |
} else {
|
|
|
105 |
$link = module_area_base::get_edit_url($err);
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$title = get_string('errorlink', manager::PLUGINNAME, $titlestr);
|
|
|
109 |
|
|
|
110 |
if (!isset($link)) {
|
|
|
111 |
debugging($err->component . ' ' . $err->tablename);
|
|
|
112 |
}
|
|
|
113 |
$out .= \html_writer::link($link, get_string('edit'), ['title' => $title]);
|
|
|
114 |
|
|
|
115 |
return $out;
|
|
|
116 |
}
|
|
|
117 |
}
|