Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 26afe886

Von Bernd Bleßmann vor fast 2 Jahren hinzugefügt

  • ID 26afe8866b70e8bcffd9d683c7243dfb18118d52
  • Vorgänger 71c8440b
  • Nachfolger 43f4f351

Benutzerdefinierte Datenexporte mit ReportGenerator

Unterschiede anzeigen:

SL/Controller/CustomDataExport.pm
12 12
use Text::CSV_XS;
13 13

  
14 14
use SL::DB::CustomDataExportQuery;
15
use SL::Controller::Helper::ReportGenerator;
15 16
use SL::Locale::String qw(t8);
16 17

  
17 18
use Rose::Object::MakeMethods::Generic
......
53 54
  $self->$method;
54 55
}
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
  my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
68

  
69
  my $report_name =  $self->query->name;
70
  $report_name    =~ s{[^[:word:]]+}{_}ig;
71
  $report_name   .=  strftime('_%Y-%m-%d_%H-%M-%S', localtime());
72

  
73
  $report->set_options(
74
    std_column_visibility => 1,
75
    controller_class      => 'CustomDataExport',
76
    output_format         => 'HTML',
77
    top_info_text         => $self->query->name,
78
    title                 => $self->query->name,
79
    allow_pdf_export      => 1,
80
    allow_csv_export      => 1,
81
    attachment_basename   => $report_name,
82
  );
83

  
84
  my %column_defs;
85
  foreach my $key (@{ $self->rows->[0] }) {
86
    $column_defs{$key} = { text => $key, sub => sub { $_[0]->{$key} } };
87
  }
88

  
89
  $report->set_columns(%column_defs);
90
  $report->set_column_order(@{ $self->rows->[0] });
91

  
92
  $report->set_export_options(qw(export_with_rep_gen id parameters));
93
  $report->set_options_from_form;
94

  
95
  # Setup data objects (which in this case is an array of hashes).
96
  my @objects;
97
  foreach my $set_idx (1..$#{ $self->rows }) {
98
    my %row_set;
99
    foreach my $key_idx (0..$#{ $self->rows->[0] }) {
100
      my $key   = $self->rows->[0]->[$key_idx];
101
      my $value = $self->rows->[$set_idx]->[$key_idx];
102
      $row_set{$key} = $value;
103
    }
104
    push @objects, \%row_set;
105
  }
106

  
107
  $self->report_generator_list_objects(report => $report, objects => \@objects);
108
}
109

  
56 110
#
57 111
# filters
58 112
#
......
93 147

  
94 148
  for my $bar ($::request->layout->get('actionbar')) {
95 149
    $bar->add(
96
      action => [
97
        t8('Export'),
98
        submit    => [ '#form', { action => 'CustomDataExport/export' } ],
99
        checks    => [ 'kivi.validate_form' ],
100
        accesskey => 'enter',
150
      combobox => [
151
        action => [
152
          t8('Export'),
153
        ],
154
        action => [
155
          t8('Direct Export'),
156
          submit    => [ '#form', { action => 'CustomDataExport/export' } ],
157
          checks    => [ 'kivi.validate_form' ],
158
        ],
159
        action => [
160
          t8('Export with RepGen'),
161
          submit    => [ '#form', { action => 'CustomDataExport/export_with_rep_gen' } ],
162
          checks    => [ 'kivi.validate_form' ],
163
        ],
101 164
      ],
102 165
      action => [
103 166
        t8('Back'),

Auch abrufbar als: Unified diff