Revision 26afe886
Von Bernd Bleßmann vor etwa 2 Jahren hinzugefügt
SL/Controller/CustomDataExport.pm | ||
---|---|---|
use Text::CSV_XS;
|
||
|
||
use SL::DB::CustomDataExportQuery;
|
||
use SL::Controller::Helper::ReportGenerator;
|
||
use SL::Locale::String qw(t8);
|
||
|
||
use Rose::Object::MakeMethods::Generic
|
||
... | ... | |
$self->$method;
|
||
}
|
||
|
||
sub action_export_with_rep_gen {
|
||
my ($self) = @_;
|
||
|
||
$self->execute_query;
|
||
|
||
if (scalar(@{ $self->rows // [] }) == 1) {
|
||
$self->setup_empty_result_set_action_bar;
|
||
return $self->render('custom_data_export/empty_result_set', title => t8("Execute custom data export '#1'", $self->query->name));
|
||
}
|
||
|
||
my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
|
||
|
||
my $report_name = $self->query->name;
|
||
$report_name =~ s{[^[:word:]]+}{_}ig;
|
||
$report_name .= strftime('_%Y-%m-%d_%H-%M-%S', localtime());
|
||
|
||
$report->set_options(
|
||
std_column_visibility => 1,
|
||
controller_class => 'CustomDataExport',
|
||
output_format => 'HTML',
|
||
top_info_text => $self->query->name,
|
||
title => $self->query->name,
|
||
allow_pdf_export => 1,
|
||
allow_csv_export => 1,
|
||
attachment_basename => $report_name,
|
||
);
|
||
|
||
my %column_defs;
|
||
foreach my $key (@{ $self->rows->[0] }) {
|
||
$column_defs{$key} = { text => $key, sub => sub { $_[0]->{$key} } };
|
||
}
|
||
|
||
$report->set_columns(%column_defs);
|
||
$report->set_column_order(@{ $self->rows->[0] });
|
||
|
||
$report->set_export_options(qw(export_with_rep_gen id parameters));
|
||
$report->set_options_from_form;
|
||
|
||
# Setup data objects (which in this case is an array of hashes).
|
||
my @objects;
|
||
foreach my $set_idx (1..$#{ $self->rows }) {
|
||
my %row_set;
|
||
foreach my $key_idx (0..$#{ $self->rows->[0] }) {
|
||
my $key = $self->rows->[0]->[$key_idx];
|
||
my $value = $self->rows->[$set_idx]->[$key_idx];
|
||
$row_set{$key} = $value;
|
||
}
|
||
push @objects, \%row_set;
|
||
}
|
||
|
||
$self->report_generator_list_objects(report => $report, objects => \@objects);
|
||
}
|
||
|
||
#
|
||
# filters
|
||
#
|
||
... | ... | |
|
||
for my $bar ($::request->layout->get('actionbar')) {
|
||
$bar->add(
|
||
action => [
|
||
t8('Export'),
|
||
submit => [ '#form', { action => 'CustomDataExport/export' } ],
|
||
checks => [ 'kivi.validate_form' ],
|
||
accesskey => 'enter',
|
||
combobox => [
|
||
action => [
|
||
t8('Export'),
|
||
],
|
||
action => [
|
||
t8('Direct Export'),
|
||
submit => [ '#form', { action => 'CustomDataExport/export' } ],
|
||
checks => [ 'kivi.validate_form' ],
|
||
],
|
||
action => [
|
||
t8('Export with RepGen'),
|
||
submit => [ '#form', { action => 'CustomDataExport/export_with_rep_gen' } ],
|
||
checks => [ 'kivi.validate_form' ],
|
||
],
|
||
],
|
||
action => [
|
||
t8('Back'),
|
Auch abrufbar als: Unified diff
Benutzerdefinierte Datenexporte mit ReportGenerator