Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 07fe52c9

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 07fe52c90951ac7fd80bc89a216f40d5919c48ab
  • Vorgänger 03d13734
  • Nachfolger 050ff24c

S:C:H:ReportGenerator: Kontroll-Zeile angeben können.

Diese kann entweder einen Separator oder andere Daten enthalten.

Unterschiede anzeigen:

SL/Controller/Helper/ReportGenerator.pm
4 4

  
5 5
use Carp;
6 6
use List::Util qw(max);
7
use List::MoreUtils qw(pairwise);
7 8

  
8 9
use SL::Common;
9 10
use SL::MoreCommon;
......
13 14
our @EXPORT = qw(
14 15
  action_report_generator_export_as_pdf action_report_generator_export_as_csv
15 16
  action_report_generator_back report_generator_do
16
  report_generator_list_objects
17
  report_generator_list_objects report_generator_make_control_row
17 18
);
18 19

  
19 20
sub _setup_action_bar {
......
114 115
  $self->_run_action($nextsub);
115 116
}
116 117

  
118
# helper class. should be moved to own module
119
{ package SL::Controller::Helper::ReportGenerator::ControlRow;
120

  
121
  my $_is_separator;
122
  my $_data;
123

  
124
  sub new {
125
    my $package       = shift;
126
    my $self          = bless {}, $package;
127

  
128
    my %params        = @_;
129

  
130
    $self->{params}   = \%params;
131

  
132
    return $self;
133
  }
134

  
135
  sub is_separator { $_[0]->{params}->{is_separator}; }
136
  sub data         { $_[0]->{params}->{data}; }
137
}
138

  
139
sub report_generator_make_control_row {
140
  my ($self, %params) = @_;
141

  
142
  return SL::Controller::Helper::ReportGenerator::ControlRow->new(is_separator => $params{is_separator}) if $params{is_separator};
143
  return SL::Controller::Helper::ReportGenerator::ControlRow->new(data         => $params{data})         if $params{data};
144

  
145
  return;
146
}
147

  
117 148
sub report_generator_list_objects {
118 149
  my ($self, %params) = @_;
119 150

  
......
126 157
  my @columns     = $params{report}->get_visible_columns('HTML');
127 158

  
128 159
  for my $obj (@{ $params{objects} || [] }) {
129
    my %data = map {
130
      my $def = $column_defs->{$_};
131
      my $tmp;
132
      $tmp->{raw_data} = $def->{raw_data} ? $def->{raw_data}->($obj) : '';
133
      $tmp->{data}     = $def->{sub}      ? $def->{sub}->($obj)
134
                       : $obj->can($_)    ? $obj->$_
135
                       :                    $obj->{$_};
136
      $tmp->{link}     = $def->{obj_link} ? $def->{obj_link}->($obj) : '';
137
      $_ => $tmp;
138
    } @columns;
160
    my %data;
161

  
162
    if ('SL::Controller::Helper::ReportGenerator::ControlRow' eq ref $obj && $obj->is_separator) {
163
      $params{report}->add_separator();
164
      next;
165
    }
166

  
167
    if ('SL::Controller::Helper::ReportGenerator::ControlRow' eq ref $obj && $obj->data) {
168
      %data = map {
169
        my $tmp;
170
        $tmp->{data} = $obj->data->{$_};
171
        $_ => $tmp;
172
      } keys %{ $obj->data };
173

  
174
    } else {
175
      %data = map {
176
        my $def = $column_defs->{$_};
177
        my $tmp;
178
        $tmp->{raw_data} = $def->{raw_data} ? $def->{raw_data}->($obj) : '';
179
        $tmp->{data}     = $def->{sub}      ? $def->{sub}->($obj)
180
                         : $obj->can($_)    ? $obj->$_
181
                         :                    $obj->{$_};
182
        $tmp->{link}     = $def->{obj_link} ? $def->{obj_link}->($obj) : '';
183
        $_ => $tmp;
184
      } @columns;
185
    }
139 186

  
140 187
    $params{data_callback}->(\%data) if $params{data_callback};
141 188

  

Auch abrufbar als: Unified diff