From 69fe35ad0181f531484c3998f931067a3b24fb97 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 --- .../intranet-tmpl/prog/en/includes/reports-toolbar.inc | 3 +++ reports/guided_reports.pl | 10 +++++++++- 2 files changed, 12 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 f75a7d7fb5..4a0ebeeac3 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 88c09207ad..ddf009c4b9 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -882,7 +882,8 @@ elsif ($phase eq 'Run this report'){ my ( $sth2, $errors2 ) = execute_query( { sql => $sql, report_id => $report_id } ); 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( @@ -981,6 +982,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