Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / Controller / Helper / ReportGenerator / ControlRow / SimpleData.pm
1 package SL::Controller::Helper::ReportGenerator::ControlRow::SimpleData;
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 "simple_data" needs a parameter "data" as hash ref' if !$self->params->{data} || ('HASH' ne ref $self->params->{data});
13
14   return @errors;
15 }
16
17 sub set_data {
18   my ($self, $report) = @_;
19
20   my %data = map {
21     my $tmp;
22     $tmp->{data} = $self->params->{data}->{$_};
23     $_ => $tmp;
24   } keys %{ $self->params->{data} };
25
26   $report->add_data(\%data);
27 }
28
29
30 1;
31
32
33 __END__
34
35 =encoding utf-8
36
37 =head1 NAME
38
39 SL::Controller::Helper::ReportGenerator::ControlRow::SimpleData - an
40 implementaion of a control row class to display simple data
41
42 =head1 DESCRIPTION
43
44 This class implements a control row for the report generator helper to display
45 simple data. C<Simple> because you only have to provide the column and your data
46 as a string.
47
48 =head1 SYNOPSIS
49
50   use SL::Controller::Helper::ReportGenerator;
51   use SL::Controller::Helper::ReportGenerator::ControlRow qw(make_control_row);
52
53   sub action_list {
54     my ($self) = @_;
55
56     # Set up the report generator instance. In this example this is
57     # hidden in "prepare_report".
58     my $report = $self->prepare_report;
59
60     # Get objects from database.
61     my $objects = SL::DB::Manager::TimeRecording->get_all(...);
62
63     # Add a simple data
64     push @$objects, make_control_row(
65       "simple_data",
66       data => { duration => 'Total sum of duration is not implemeted yet' }
67     );
68
69     # Let report generator create the output.
70     $self->report_generator_list_objects(
71       report  => $report,
72       objects => $objects,
73     );
74   }
75
76 =head1 PARAMETERS
77
78 This control row gets the paramter C<data>, which must a hash ref.
79 The keys are the column names for the fields you want to show your
80 data. The values are the data.
81
82 =head1 AUTHOR
83
84 Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
85
86 =cut