Skip to content

Commit 1af9772

Browse files
committed
feat: add report export
1 parent d350cdf commit 1af9772

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

classes/table/csp_report.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ private function format_uri($uri, $label = '', $size = 40) {
131131
}
132132
$label = str_replace($CFG->wwwroot, '', $label);
133133
$label = ltrim($label, '/');
134-
$label = shorten_text($label, $size, true);
134+
135+
// Only shorten text when not exporting.
136+
if(!$this->is_downloading()) {
137+
$label = shorten_text($label, $size, true);
138+
}
135139
$label = s($label);
136140

137141
return \html_writer::link($uri, $label);
@@ -287,6 +291,11 @@ protected function col_courses($record) {
287291
* @return string HTML link.
288292
*/
289293
protected function col_action($record) {
294+
// Output no action if exporting.
295+
if($this->is_downloading()) {
296+
return '';
297+
}
298+
290299
global $OUTPUT;
291300

292301
// Find whether we are drilling down.

csp_report.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
$removedirective = optional_param('removedirective', false, PARAM_TEXT);
3434
$removedomain = optional_param('removedomain', false, PARAM_TEXT);
3535
$removerecordwithid = optional_param('removerecordwithid', false, PARAM_TEXT);
36+
$download = optional_param('download', '', PARAM_ALPHA);
3637

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

@@ -58,6 +59,14 @@
5859
redirect($PAGE->url);
5960
}
6061

62+
$PAGE->set_url('/local/csp/csp_report.php', [
63+
'blockeddomain' => $viewblockeddomain,
64+
'blockeddirective' => $viewdirective ?? '',
65+
'removedirective' => $removedirective,
66+
'removedomain' => $removedomain,
67+
'removerecordwithid' => $removerecordwithid,
68+
]);
69+
6170
$resetallcspstatistics = optional_param('resetallcspstatistics', 0, PARAM_INT);
6271
if ($resetallcspstatistics == 1 && confirm_sesskey()) {
6372
$DB->delete_records('local_csp');
@@ -69,18 +78,10 @@
6978
$PAGE->set_heading($title);
7079
$PAGE->set_pagelayout('admin');
7180

72-
global $OUTPUT, $DB;
73-
74-
echo $OUTPUT->header();
75-
echo $OUTPUT->heading($title);
81+
$table = new \local_csp\table\csp_report('cspreportstable');
82+
$table->is_downloading($download, 'csp_report', 'csp_report');
7683

77-
$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
78-
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
79-
'resetallcspstatistics' => 1,
80-
'sesskey' => sesskey(),
81-
));
82-
echo $OUTPUT->single_button($urlresetallcspstatistics,
83-
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
84+
global $OUTPUT, $DB;
8485

8586
$blockeduri = get_string('blockeduri', 'local_csp');
8687
$blockeddomain = get_string('blockeddomain', 'local_csp');
@@ -93,7 +94,6 @@
9394
$timeupdated = get_string('timeupdated', 'local_csp');
9495
$action = get_string('action', 'local_csp');
9596

96-
$table = new \local_csp\table\csp_report('cspreportstable');
9797
$table->define_baseurl($PAGE->url);
9898
$table->sortable(true, 'failcounter', SORT_DESC);
9999
$table->set_attribute('class', 'generaltable generalbox table-sm');
@@ -159,8 +159,21 @@
159159
$where = '1 = 1';
160160
$params = array();
161161
}
162-
$table->set_sql($fields, $from, $where, $params);
163162

163+
if(!$table->is_downloading()) {
164+
echo $OUTPUT->header();
165+
echo $OUTPUT->heading($title);
166+
167+
$action = new \confirm_action(get_string('areyousuretodeleteallrecords', 'local_csp'));
168+
$urlresetallcspstatistics = new moodle_url($PAGE->url, array(
169+
'resetallcspstatistics' => 1,
170+
'sesskey' => sesskey(),
171+
));
172+
echo $OUTPUT->single_button($urlresetallcspstatistics,
173+
get_string('resetallcspstatistics', 'local_csp'), 'post', array('actions' => array($action)));
174+
}
175+
176+
$table->set_sql($fields, $from, $where, $params);
164177
$table->out(30, true);
165178

166179
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)