159249d1ad3a46ab3609a14ef657bbb8a8e835ee
[kivitendo-erp.git] / SL / Controller / Helper / ReportGenerator / ControlRow / Data.pm
1 package SL::Controller::Helper::ReportGenerator::ControlRow::Data;
2
3 use strict;
4
5 use parent qw(SL::Controller::Helper::ReportGenerator::ControlRow::Base);
6
7
8 sub validate_params {
9   my ($self) = @_;
10
11   my @errors;
12   push @errors, 'type "data" needs a parameter "row" as hash ref' if !$self->params->{row} || ('HASH' ne ref $self->params->{row});
13
14   return @errors;;
15 }
16
17 sub set_data {
18   my ($self, $report) = @_;
19
20   my %data;
21   %data = map {
22     my $def = $self->params->{row}->{$_};
23     my $tmp;
24
25     foreach my $attr (qw(raw_data data link class align)) {
26       $tmp->{$attr} = $def->{$attr} if defined $def->{$attr};
27     }
28     $_ => $tmp;
29   } keys %{ $self->params->{row} };
30
31   $report->add_data(\%data);
32 }
33
34
35 1;
36
37 __END__
38
39 =encoding utf-8
40
41 =head1 NAME
42
43 SL::Controller::Helper::ReportGenerator::ControlRow::Data - an
44 implementaion of a control row class to display data
45
46 =head1 DESCRIPTION
47
48 This class implements a control row for the report generator helper to display
49 data. You can configure the way the data is displayed.
50
51 =head1 SYNOPSIS
52
53   use SL::Controller::Helper::ReportGenerator;
54   use SL::Controller::Helper::ReportGenerator::ControlRow qw(make_control_row);
55
56   sub action_list {
57     my ($self) = @_;
58
59     # Set up the report generator instance. In this example this is
60     # hidden in "prepare_report".
61     my $report = $self->prepare_report;
62
63     # Get objects from database.
64     my $objects = SL::DB::Manager::TimeRecording->get_all(...);
65
66     # Add a simple data
67     my $total = $self->get_total($objects);
68     push @$objects, make_control_row(
69       "data",
70       row => { duration => { data  => $total,
71                              class => 'listtotal',
72                              link  => '#info_for_total' } }
73     );
74
75     # Let report generator create the output.
76     $self->report_generator_list_objects(
77       report  => $report,
78       objects => $objects,
79     );
80   }
81
82 =head1 PARAMETERS
83
84 This control row gets the paramter C<row>, which must a hash ref.
85 The keys are the column names for the fields you want to show your
86 data. The values are hash refs itself and can contain the keys
87 C<raw_data>, C<data>, C<link>, C<class> and C<align> which are passed
88 in the data added to the report.
89
90 =head1 AUTHOR
91
92 Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
93
94 =cut