X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/39e13b0fb4b323c1d8c691b0e55c37d0ca1becc5..e055b3ff9423767fd109a8d7a36d354c8997c941:/SL/Controller/CsvImport/Base.pm diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 0381b4b0b..91efaaaac 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -11,7 +11,7 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(controller file csv) ], - 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class) ], + 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ], ); sub run { @@ -72,6 +72,43 @@ sub add_raw_data_columns { } } +sub add_cvar_raw_data_columns { + my ($self) = @_; + + map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->cvar_columns }; +} + +sub init_cvar_columns { + my ($self) = @_; + + return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ]; +} + +sub handle_cvars { + my ($self, $entry) = @_; + + return unless $self->can('all_cvar_configs'); + + my %type_to_column = ( text => 'text_value', + textfield => 'text_value', + select => 'text_value', + date => 'timestamp_value_as_date', + timestamp => 'timestamp_value_as_date', + number => 'number_value_as_number', + bool => 'bool_value' ); + + my @cvars; + foreach my $config (@{ $self->all_cvar_configs }) { + next unless exists $entry->{raw_data}->{ "cvar_" . $config->name }; + my $value = $entry->{raw_data}->{ "cvar_" . $config->name }; + my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type"; + + push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value); + } + + $entry->{object}->custom_variables(\@cvars); +} + sub init_profile { my ($self) = @_;