mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-74140' of https://github.com/paulholden/moodle
This commit is contained in:
commit
5378c89521
3 changed files with 83 additions and 8 deletions
|
@ -151,14 +151,11 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override parent method of the same, to make use of a recordset and avoid issues with duplicate values in the first column
|
* Generate suitable SQL for the table
|
||||||
*
|
*
|
||||||
* @param int $pagesize
|
* @return string
|
||||||
* @param bool $useinitialsbar
|
|
||||||
*/
|
*/
|
||||||
public function query_db($pagesize, $useinitialsbar = true) {
|
protected function get_table_sql(): string {
|
||||||
global $DB;
|
|
||||||
|
|
||||||
$sql = "SELECT {$this->sql->fields} FROM {$this->sql->from} WHERE {$this->sql->where} {$this->groupbysql}";
|
$sql = "SELECT {$this->sql->fields} FROM {$this->sql->from} WHERE {$this->sql->where} {$this->groupbysql}";
|
||||||
|
|
||||||
$sort = $this->get_sql_sort();
|
$sort = $this->get_sql_sort();
|
||||||
|
@ -166,12 +163,25 @@ abstract class base_report_table extends table_sql implements dynamic, renderabl
|
||||||
$sql .= " ORDER BY {$sort}";
|
$sql .= " ORDER BY {$sort}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override parent method of the same, to make use of a recordset and avoid issues with duplicate values in the first column
|
||||||
|
*
|
||||||
|
* @param int $pagesize
|
||||||
|
* @param bool $useinitialsbar
|
||||||
|
*/
|
||||||
|
public function query_db($pagesize, $useinitialsbar = true): void {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
if (!$this->is_downloading()) {
|
if (!$this->is_downloading()) {
|
||||||
$this->pagesize($pagesize, $DB->count_records_sql($this->countsql, $this->countparams));
|
$this->pagesize($pagesize, $DB->count_records_sql($this->countsql, $this->countparams));
|
||||||
|
|
||||||
$this->rawdata = $DB->get_recordset_sql($sql, $this->sql->params, $this->get_page_start(), $this->get_page_size());
|
$this->rawdata = $DB->get_recordset_sql($this->get_table_sql(), $this->sql->params, $this->get_page_start(),
|
||||||
|
$this->get_page_size());
|
||||||
} else {
|
} else {
|
||||||
$this->rawdata = $DB->get_recordset_sql($sql, $this->sql->params);
|
$this->rawdata = $DB->get_recordset_sql($this->get_table_sql(), $this->sql->params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ class custom_report_table extends base_report_table {
|
||||||
/** @var bool Whether report is being edited (we don't want user filters/sorting to be applied when editing) */
|
/** @var bool Whether report is being edited (we don't want user filters/sorting to be applied when editing) */
|
||||||
protected const REPORT_EDITING = true;
|
protected const REPORT_EDITING = true;
|
||||||
|
|
||||||
|
/** @var float $querytimestart Time we began executing table SQL */
|
||||||
|
private $querytimestart = 0.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table constructor. Note that the passed unique ID value must match the pattern "custom-report-table-(\d+)" so that
|
* Table constructor. Note that the passed unique ID value must match the pattern "custom-report-table-(\d+)" so that
|
||||||
* dynamic updates continue to load the same report
|
* dynamic updates continue to load the same report
|
||||||
|
@ -298,6 +301,26 @@ class custom_report_table extends base_report_table {
|
||||||
echo $this->get_dynamic_table_html_end();
|
echo $this->get_dynamic_table_html_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide additional table debugging during editing
|
||||||
|
*/
|
||||||
|
public function wrap_html_finish(): void {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
if ($this->editing && debugging('', DEBUG_DEVELOPER)) {
|
||||||
|
$params = array_map(static function(string $param, $value): array {
|
||||||
|
return ['param' => $param, 'value' => var_export($value, true)];
|
||||||
|
}, array_keys($this->sql->params), $this->sql->params);
|
||||||
|
|
||||||
|
echo $OUTPUT->render_from_template('core_reportbuilder/local/report/debug', [
|
||||||
|
'query' => $this->get_table_sql(),
|
||||||
|
'params' => $params,
|
||||||
|
'duration' => $this->querytimestart ?
|
||||||
|
format_time($this->querytimestart - microtime(true)) : null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override get_row_cells_html to add an extra cell with the toggle button for card view.
|
* Override get_row_cells_html to add an extra cell with the toggle button for card view.
|
||||||
*
|
*
|
||||||
|
@ -338,6 +361,7 @@ class custom_report_table extends base_report_table {
|
||||||
|
|
||||||
// If the live editing setting is disabled, we not need to fetch custom report data except in preview mode.
|
// If the live editing setting is disabled, we not need to fetch custom report data except in preview mode.
|
||||||
if (!$this->editing || self::show_live_editing()) {
|
if (!$this->editing || self::show_live_editing()) {
|
||||||
|
$this->querytimestart = microtime(true);
|
||||||
$this->query_db($pagesize, $useinitialsbar);
|
$this->query_db($pagesize, $useinitialsbar);
|
||||||
$this->build_table();
|
$this->build_table();
|
||||||
$this->close_recordset();
|
$this->close_recordset();
|
||||||
|
|
41
reportbuilder/templates/local/report/debug.mustache
Normal file
41
reportbuilder/templates/local/report/debug.mustache
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{{!
|
||||||
|
This file is part of Moodle - http://moodle.org/
|
||||||
|
|
||||||
|
Moodle is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Moodle is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
}}
|
||||||
|
{{!
|
||||||
|
@template core_reportbuilder/local/report/debug
|
||||||
|
|
||||||
|
Template for custom report debug
|
||||||
|
|
||||||
|
Example context (json):
|
||||||
|
{
|
||||||
|
"query": "SELECT foo FROM {bar} WHERE baz = :rbparam1",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"param": "rbparam1",
|
||||||
|
"value": 42
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"duration": "0.124 secs"
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
<details>
|
||||||
|
<summary>{{#str}} debuginfo, core_debug {{/str}}</summary>
|
||||||
|
<code class="d-block mb-2">{{query}}</code>
|
||||||
|
{{#params}}
|
||||||
|
<code class="d-block mb-2">{{param}} => {{value}}</code>
|
||||||
|
{{/params}}
|
||||||
|
{{#duration}}<code class="d-block">{{.}}</code>{{/duration}}
|
||||||
|
</details>
|
Loading…
Add table
Add a link
Reference in a new issue