1 package SL::DB::Helper::LegacyPrinting;
5 use parent qw(Exporter);
6 our @EXPORT = qw(map_keys_to_arrays format_as_number);
8 sub map_keys_to_arrays {
9 my ($items, $keys, $template_arrays) = @_;
11 for my $key (@$keys) {
14 my ($k1, $k2) = split /\./, $key;
15 $template_arrays->{$k1} = [ map { { $k2 => $_->{$k1}->{$k2} } } @$items ];
17 $template_arrays->{$key} = [ map {
18 if (ref $_ eq 'HASH') {
21 $_->can($key) ? $_->$key
29 sub format_as_number {
30 my ($keys, $template_arrays) = @_;
32 for my $key (@$keys) {
33 $template_arrays->{$key} = [ map {
34 $::form->format_amount(\%::myconfig, $_, 2, 0),
35 } @{ $template_arrays->{$key} } ];
49 SL::DB::Helper::LegacyPrinting - Helper functions to support printing using the built-it template parser
53 The new Reclamation controller, and possibly other future controllers, only support printing using Template Toolkit (TT)
54 for parsing the templates. For OpenDocument templates however, template toolkit cannot be used.
56 Template Toolkit (TT) can access Rose DB objects directly, which is a feature not available in the built-in parser.
57 For positions in a loop, such as positions in a table, the built-in parser expects the data in a specific format.
58 Therefore, we need to prepare the data accordingly before it can be processed by the built-in parser.
60 In the past this was done in the respective modules, e.g. SL/OE.pm. The idea would be to extract the data from the Rose
61 DB objects. That should hopefully result in less and simpler code.
65 =head2 C<map_keys_to_arrays ($items, $keys, $template_arrays)>
67 Extracts the given keys from the given list of Rose DB objects and adds them to the given hash reference,
68 in the format that the built in template parser expects.
70 The expected format looks like the following, e.g.:
72 # 'qty_as_number' => [
78 # 'partnumber' => '000013'
81 # 'partnumber' => '000004'
97 A reference to a list of Rose DB objects from which the keys should be extracted.
101 A reference to a list of keys that should be extracted from the Rose DB object.
102 Nested keys should be denoted by a dot. E.g.:
104 qw( qty_as_number part.partnumber position unit )
106 =item C<$template_arrays>
108 A reference to a hash to which the extracted keys should be added.
112 =head2 C<format_as_number ($keys, $template_arrays)>
114 Formats the given keys in the given hash reference as numbers.
118 Cem Aydin E<lt>cem.aydin@revamp-it.chE<gt>