Skip to content

Commit

Permalink
feat: add report export
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Jul 5, 2024
1 parent 9aad97b commit 9f13d12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
11 changes: 10 additions & 1 deletion classes/table/csp_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ private function format_uri($uri, $label = '', $size = 40) {
}
$label = str_replace($CFG->wwwroot, '', $label);
$label = ltrim($label, '/');
$label = shorten_text($label, $size, true);

// Only shorten text when not exporting.
if(!$this->is_downloading()) {
$label = shorten_text($label, $size, true);
}
$label = s($label);

return \html_writer::link($uri, $label);
Expand Down Expand Up @@ -287,6 +291,11 @@ protected function col_courses($record) {
* @return string HTML link.
*/
protected function col_action($record) {
// Output no action if exporting.
if($this->is_downloading()) {
return '';
}

global $OUTPUT;

// Find whether we are drilling down.
Expand Down
39 changes: 26 additions & 13 deletions csp_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$removedirective = optional_param('removedirective', false, PARAM_TEXT);
$removedomain = optional_param('removedomain', false, PARAM_TEXT);
$removerecordwithid = optional_param('removerecordwithid', false, PARAM_TEXT);
$download = optional_param('download', '', PARAM_ALPHA);

admin_externalpage_setup('local_csp_report', '', null, '', array('pagelayout' => 'report'));

Expand All @@ -58,6 +59,14 @@
redirect($PAGE->url);
}

$PAGE->set_url('/local/csp/csp_report.php', [
'blockeddomain' => $viewblockeddomain,
'blockeddirective' => $viewdirective ?? '',
'removedirective' => $removedirective,
'removedomain' => $removedomain,
'removerecordwithid' => $removerecordwithid,
]);

$resetallcspstatistics = optional_param('resetallcspstatistics', 0, PARAM_INT);
if ($resetallcspstatistics == 1 && confirm_sesskey()) {
$DB->delete_records('local_csp');
Expand All @@ -69,18 +78,10 @@
$PAGE->set_heading($title);
$PAGE->set_pagelayout('admin');

global $OUTPUT, $DB;

echo $OUTPUT->header();
echo $OUTPUT->heading($title);
$table = new \local_csp\table\csp_report('cspreportstable');
$table->is_downloading($download, 'csp_report', 'csp_report');

$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
'resetallcspstatistics' => 1,
'sesskey' => sesskey(),
));
echo $OUTPUT->single_button($urlresetallcspstatistics,
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
global $OUTPUT, $DB;

$blockeduri = get_string('blockeduri', 'local_csp');
$blockeddomain = get_string('blockeddomain', 'local_csp');
Expand All @@ -93,7 +94,6 @@
$timeupdated = get_string('timeupdated', 'local_csp');
$action = get_string('action', 'local_csp');

$table = new \local_csp\table\csp_report('cspreportstable');
$table->define_baseurl($PAGE->url);
$table->sortable(true, 'failcounter', SORT_DESC);
$table->set_attribute('class', 'generaltable generalbox table-sm');
Expand Down Expand Up @@ -159,8 +159,21 @@
$where = '1 = 1';
$params = array();
}
$table->set_sql($fields, $from, $where, $params);

if(!$table->is_downloading()) {
echo $OUTPUT->header();
echo $OUTPUT->heading($title);

$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
'resetallcspstatistics' => 1,
'sesskey' => sesskey(),
));
echo $OUTPUT->single_button($urlresetallcspstatistics,
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
}

$table->set_sql($fields, $from, $where, $params);
$table->out(30, true);

echo $OUTPUT->footer();

0 comments on commit 9f13d12

Please sign in to comment.