Skip to content

Commit

Permalink
Ad-hoc queries: sheduled query results improvements #741160
Browse files Browse the repository at this point in the history
1. Now, we default to showing the results for the most recent time
the query should have run, so it is cearer if there are no results.

2. I improved the heading above the list of past results.

3. And fixed the logic for when that list displays.

4. Use consistent date format throught the report.
  • Loading branch information
timhunt committed Dec 13, 2023
1 parent 7e67d5e commit 7e84ecf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
3 changes: 2 additions & 1 deletion lang/en/report_customsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$string['addreport'] = 'Add a new query';
$string['addreportcategory'] = 'Add a new category for reports';
$string['anyonewhocanveiwthisreport'] = 'Anyone who can view this report (report/customsql:view)';
$string['archivedversions'] = 'Archived versions of this query';
$string['archivedversions'] = 'Results of this query at other times';
$string['at'] = 'at';
$string['automaticallydaily'] = 'Scheduled, daily';
$string['automaticallymonthly'] = 'Scheduled, on the first day of each month';
Expand Down Expand Up @@ -108,6 +108,7 @@
$string['noscheduleifplaceholders'] = 'Queries containing placeholders can only be run on-demand.';
$string['nosemicolon'] = 'You are not allowed a ; character in the SQL.';
$string['notallowedwords'] = 'You are not allowed to use the words <code>{$a}</code> in the SQL.';
$string['notanyresults'] = 'This query did not return any results on {$a}.';
$string['note'] = 'Notes';
$string['notrunyet'] = 'This query has not yet been run.';
$string['onerow'] = 'The query returns one row, accumulate the results one row at a time';
Expand Down
50 changes: 28 additions & 22 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@
// Runs on schedule.
$csvtimestamp = optional_param('timestamp', null, PARAM_INT);
if ($csvtimestamp === null) {
$archivetimes = report_customsql_get_archive_times($report);
$csvtimestamp = array_shift($archivetimes);
}
if ($csvtimestamp === null) {
$csvtimestamp = time();
[$csvtimestamp] = report_customsql_get_starts($report, time());
}
$urlparams['timestamp'] = $csvtimestamp;
}
Expand Down Expand Up @@ -171,13 +167,17 @@
} else {
list($csvfilename, $csvtimestamp) = report_customsql_csv_filename($report, $csvtimestamp);
if (!is_readable($csvfilename)) {
echo html_writer::tag('p', get_string('notrunyet', 'report_customsql'));
if (empty($report->lastrun) || $csvtimestamp > $report->lastrun) {
echo html_writer::tag('p', get_string('notrunyet', 'report_customsql'));
} else {
echo html_writer::tag('p', get_string('notanyresults', 'report_customsql', userdate($csvtimestamp)));
}
} else {
$handle = fopen($csvfilename, 'r');

if ($report->runable != 'manual' && !$report->singlerow) {
echo $OUTPUT->heading(get_string('reportfor', 'report_customsql',
userdate($csvtimestamp, get_string('strftimedate'))), 3);
userdate($csvtimestamp)), 3);
}

$table = new html_table();
Expand Down Expand Up @@ -237,23 +237,29 @@

echo $output->render_report_actions($report, $category, $context);

$archivetimes = report_customsql_get_archive_times($report);
if (count($archivetimes) > 1) {
echo $OUTPUT->heading(get_string('archivedversions', 'report_customsql'), 3).
html_writer::start_tag('ul');
foreach ($archivetimes as $time) {
$formattedtime = userdate($time, get_string('strftimedate'));
echo html_writer::start_tag('li');
if ($time == $csvtimestamp) {
echo html_writer::tag('b', $formattedtime);
} else {
echo html_writer::tag('a', $formattedtime,
array('href' => report_customsql_url('view.php',
['id' => $id, 'timestamp' => $time])));
if ($report->runable != 'manual') {
echo $OUTPUT->heading(get_string('archivedversions', 'report_customsql'), 3);

$archivetimes = report_customsql_get_archive_times($report);
if (!$archivetimes) {
echo html_writer::tag('p', get_string('notrunyet', 'report_customsql'));

} else {
echo html_writer::start_tag('ul');
foreach ($archivetimes as $time) {
$formattedtime = userdate($time);
echo html_writer::start_tag('li');
if ($time == $csvtimestamp) {
echo html_writer::tag('b', $formattedtime);
} else {
echo html_writer::tag('a', $formattedtime,
array('href' => report_customsql_url('view.php',
['id' => $id, 'timestamp' => $time])));
}
echo '</li>';
}
echo '</li>';
echo html_writer::end_tag('ul');
}
echo html_writer::end_tag('ul');
}

echo $OUTPUT->footer();

0 comments on commit 7e84ecf

Please sign in to comment.