From 9dfe6ff495366e73a253e32ee9a1e17ebf5e97ed Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 2 Aug 2023 07:56:46 -0400 Subject: [PATCH] Bug 34456: Add the ability to download a template rendered report as a file Bug 34136 adds the ability to render a report using a notice template rather than displaying data in a table. It would be even more useful to be able to download the contents as a file where the notice subject can be used as the filename so the filename can be generated dynamically ( such as adding the current date as part of the filename ). Test Plan: 1) Follow the test plan for Bug 34136 2) Run your report 3) Note under the Download menu the new item "Download as" with the subject line for your template 4) Click that link, note the file contains the contents of your report! Signed-off-by: Sam Lau --- .../prog/en/includes/reports-toolbar.inc | 3 +++ reports/guided_reports.pl | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc index de76725e8c1..70954f7b863 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc @@ -134,6 +134,9 @@
  • [% PROCESS 'delimiter_text.inc' %]
  • Tab separated text
  • Open Document Spreadsheet
  • + [% IF processed_notice_title %] +
  • Download as [% processed_notice_title | html %]
  • + [% END %] [% IF (results.json) %]
  • Chart (.svg)
  • [% END %] diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 6212fdae038..c3c104aaf28 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -884,7 +884,13 @@ elsif ($phase eq 'Run this report'){ my $data = $sth2->fetchall_arrayref( {} ); my $notice_rendered = process_tt( $notice_template->content, { data => $data, report_id => $report_id } ); - $template->param( processed_notice => $notice_rendered ); + my $title_rendered = + process_tt( $notice_template->title, { data => $data, report_id => $report_id } ); + $template->param( + template_id => $template_id, + processed_notice => $notice_rendered, + processed_notice_title => $title_rendered, + ); } $template->param( @@ -983,6 +989,13 @@ elsif ($phase eq 'Export'){ $content .= $_ while <$ods_fh>; unlink $ods_filepath; } + elsif ( $format eq 'template' ) { + my $template_id = $input->param('template'); + my $notice_template = Koha::Notice::Templates->find($template_id); + my $data = $sth->fetchall_arrayref({}); + $content = process_tt( $notice_template->content, { data => $data, report_id => $report_id, for_download => 1 } ); + $reportfilename = process_tt( $notice_template->title, { data => $data, report_id => $report_id } ); + } } print $input->header( -type => $type, -- 2.30.2