Revision 231a7390
Von Bernd Bleßmann vor etwa 1 Jahr hinzugefügt
SL/Controller/CustomDataExport.pm | ||
---|---|---|
37 | 37 |
sub action_export { |
38 | 38 |
my ($self) = @_; |
39 | 39 |
|
40 |
if (!$::form->{format}) {
|
|
40 |
if (!$::form->{parameters_set}) {
|
|
41 | 41 |
$self->setup_export_action_bar; |
42 | 42 |
return $self->render('custom_data_export/export', title => t8("Execute custom data export '#1'", $self->query->name)); |
43 | 43 |
} |
... | ... | |
49 | 49 |
return $self->render('custom_data_export/empty_result_set', title => t8("Execute custom data export '#1'", $self->query->name)); |
50 | 50 |
} |
51 | 51 |
|
52 |
|
|
53 |
my $method = "export_as_" . $::form->{format}; |
|
54 |
$self->$method; |
|
55 |
} |
|
56 |
|
|
57 |
sub action_export_with_rep_gen { |
|
58 |
my ($self) = @_; |
|
59 |
|
|
60 |
$self->execute_query; |
|
61 |
|
|
62 |
if (scalar(@{ $self->rows // [] }) == 1) { |
|
63 |
$self->setup_empty_result_set_action_bar; |
|
64 |
return $self->render('custom_data_export/empty_result_set', title => t8("Execute custom data export '#1'", $self->query->name)); |
|
65 |
} |
|
66 |
|
|
67 | 52 |
my $report = SL::ReportGenerator->new(\%::myconfig, $::form); |
68 | 53 |
|
69 | 54 |
my $report_name = $self->query->name; |
... | ... | |
89 | 74 |
$report->set_columns(%column_defs); |
90 | 75 |
$report->set_column_order(@{ $self->rows->[0] }); |
91 | 76 |
|
92 |
$report->set_export_options(qw(export_with_rep_gen id parameters));
|
|
77 |
$report->set_export_options(qw(export id parameters_set parameters));
|
|
93 | 78 |
$report->set_options_from_form; |
94 | 79 |
|
95 | 80 |
# Setup data objects (which in this case is an array of hashes). |
... | ... | |
152 | 137 |
|
153 | 138 |
for my $bar ($::request->layout->get('actionbar')) { |
154 | 139 |
$bar->add( |
155 |
combobox => [ |
|
156 |
action => [ |
|
157 |
t8('Export'), |
|
158 |
], |
|
159 |
action => [ |
|
160 |
t8('Direct Export'), |
|
161 |
submit => [ '#form', { action => 'CustomDataExport/export' } ], |
|
162 |
checks => [ 'kivi.validate_form' ], |
|
163 |
], |
|
164 |
action => [ |
|
165 |
t8('Export with RepGen'), |
|
166 |
submit => [ '#form', { action => 'CustomDataExport/export_with_rep_gen' } ], |
|
167 |
checks => [ 'kivi.validate_form' ], |
|
168 |
], |
|
140 |
action => [ |
|
141 |
t8('Export'), |
|
142 |
submit => [ '#form', { action => 'CustomDataExport/export' } ], |
|
143 |
checks => [ 'kivi.validate_form' ], |
|
169 | 144 |
], |
170 | 145 |
action => [ |
171 | 146 |
t8('Back'), |
... | ... | |
238 | 213 |
]); |
239 | 214 |
} |
240 | 215 |
|
241 |
sub export_as_csv { |
|
242 |
my ($self) = @_; |
|
243 |
|
|
244 |
my $csv = Text::CSV_XS->new({ |
|
245 |
binary => 1, |
|
246 |
sep_char => ';', |
|
247 |
eol => "\n", |
|
248 |
}); |
|
249 |
|
|
250 |
my ($file_handle, $file_name) = File::Temp::tempfile; |
|
251 |
|
|
252 |
binmode $file_handle, ":encoding(utf8)"; |
|
253 |
|
|
254 |
$csv->print($file_handle, $_) for @{ $self->rows }; |
|
255 |
|
|
256 |
$file_handle->close; |
|
257 |
|
|
258 |
my $report_name = $self->query->name; |
|
259 |
$report_name =~ s{[^[:word:]]+}{_}ig; |
|
260 |
$report_name .= strftime('_%Y-%m-%d_%H-%M-%S.csv', localtime()); |
|
261 |
|
|
262 |
$self->send_file( |
|
263 |
$file_name, |
|
264 |
content_type => 'text/csv', |
|
265 |
name => $report_name, |
|
266 |
); |
|
267 |
} |
|
268 |
|
|
269 | 216 |
1; |
Auch abrufbar als: Unified diff
Benutzerdefinierte Datenexporte mit ReportGenerator: Direkten CSV-Export entfernt