S:C:H:ReportGenerator: Interface und Impmentierung von Kontroll-Zeilen
[kivitendo-erp.git] / SL / Controller / Helper / ReportGenerator / ControlRow / Base.pm
1 package SL::Controller::Helper::ReportGenerator::ControlRow::Base;
2
3 use strict;
4
5 use parent qw(SL::DB::Object);
6
7 use Rose::Object::MakeMethods::Generic (
8   scalar => [ qw(params) ],
9 );
10
11
12 sub validate_params { die 'name needs to be implemented' }
13 sub set_data        { die 'name needs to be implemented' }
14
15
16 1;
17
18
19 __END__
20
21 =encoding utf-8
22
23 =head1 NAME
24
25 SL::Controller::Helper::ReportGenerator::ControlRow::Base - a base class
26 for report generator control row classes
27
28 =head1 DESCRIPTION
29
30 ControlRow is an interface that allows generic control rows to be added
31 to objects for the C<SL::Controller::Helper::ReportGenerator>. This is a
32 base class from which all control row classes are derived.
33
34 =head1 SYNOPSIS
35
36 Adding your own new control row of the type "only_dashes":
37
38   package SL::Controller::Helper::ReportGenerator::ControlRow::OnlyDashes;
39
40   use parent qw(SL::Controller::Helper::ReportGenerator::ControlRow::Base);
41
42   sub validate_params { return; } # no params
43
44   sub set_data {
45     my ($self, $report) = @_;
46
47     my %data = map { $_ => {data => '---'} } keys %{ $report->{columns} };
48
49     $report->add_data(\%data);
50   }
51
52 After that, you have to register your new class in
53 C<SL::Controller::Helper::ReportGenerator::ControlRow::ALL>:
54
55   use SL::Controller::Helper::ReportGenerator::ControlRow::OnlyDashes;
56
57   our %type_to_class = (
58     ...,
59     only_dashes => 'SL::Controller::Helper::ReportGenerator::ControlRow::OnlyDashes',
60   );
61
62
63 =head1 WRITING OWN CONTROL ROW CLASSES
64
65 You can use C<SL::Controller::Helper::ReportGenerator::ControlRow::Base>
66 as parent of your module. You have to provide two methods:
67
68 =over 4
69
70 =item C<validate_params>
71
72 This method is used to validate any params used for your module.
73 You can access the params through the method C<params> which contains all
74 remaining params after the type of the call to make_control_row (see
75 C<SL::Controller::Helper::ReportGenerator::ControlRow>).
76
77 The method should return an array of error messages if there are any
78 errors. Otherwise it should return C<undef>.
79
80 =item C<set_data REPORT>
81
82 This method sould set the data for the report generator, which is handeled
83 over as argument.
84
85 =back
86
87 =head1 REGISTERING OWN CONTROL ROW CLASSES
88
89 See C<SL::Controller::Helper::ReportGenerator::ControlRow::ALL>. Here your
90 class should be included with C<use> and entered in the map C<%type_to_class>
91 with an appropiate name for it's type.
92
93
94 =head1 AUTHOR
95
96 Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
97
98 =cut