CsvReport: Status mitspeichern
[kivitendo-erp.git] / SL / DB / CsvImportReport.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::CsvImportReport;
5
6 use strict;
7
8 use SL::DB::MetaSetup::CsvImportReport;
9
10 __PACKAGE__->meta->add_relationships(
11   rows => {
12     type         => 'one to many',
13     class        => 'SL::DB::CsvImportReportRow',
14     column_map   => { id => 'csv_import_report_id' },
15   },
16   status => {
17     type         => 'one to many',
18     class        => 'SL::DB::CsvImportReportStatus',
19     column_map   => { id => 'csv_import_report_id' },
20   },
21 );
22
23 __PACKAGE__->meta->make_manager_class;
24 __PACKAGE__->meta->initialize;
25
26 sub folded_rows {
27   my ($self) = @_;
28
29   $self->_fold_rows unless $self->{folded_rows};
30
31   return $self->{folded_rows};
32 }
33
34 sub folded_status {
35   my ($self) = @_;
36
37   $self->_fold_status unless $self->{folded_status};
38
39   return $self->{folded_status};
40 }
41
42 sub _fold_rows {
43   my ($self) = @_;
44
45   $self->{folded_rows} = [];
46
47   for my $row_obj (@{ $self->rows }) {
48     $self->{folded_rows}->[ $row_obj->row ] ||= [];
49     $self->{folded_rows}->[ $row_obj->row ][ $row_obj->col ] = $row_obj->value;
50   }
51 }
52
53 sub _fold_status {
54   my ($self) = @_;
55
56   $self->{folded_status} = [];
57
58   for my $status_obj (@{ $self->status }) {
59     $self->{folded_status}->[ $status_obj->row ] ||= {};
60     $self->{folded_status}->[ $status_obj->row ]{information} ||= [];
61     $self->{folded_status}->[ $status_obj->row ]{errors} ||= [];
62     push @{ $self->{folded_status}->[ $status_obj->row ]{ $status_obj->type } }, $status_obj->value;
63   }
64 }
65
66 1;