X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FCustomVariableConfig.pm;h=203f83a90d0a374d7725dc680a812a86cf727e5d;hb=89ade8da54d47af2cbf100fac07bf88ed9f23c43;hp=3410a496621e1075314683c3135b26fe9b940ca9;hpb=f9676efea9ccfa01df2a57dca9c45cc8fde0d09e;p=kivitendo-erp.git diff --git a/SL/DB/CustomVariableConfig.pm b/SL/DB/CustomVariableConfig.pm index 3410a4966..203f83a90 100644 --- a/SL/DB/CustomVariableConfig.pm +++ b/SL/DB/CustomVariableConfig.pm @@ -6,8 +6,85 @@ package SL::DB::CustomVariableConfig; use strict; use SL::DB::MetaSetup::CustomVariableConfig; +use SL::DB::Manager::CustomVariableConfig; +use SL::DB::Helper::ActsAsList; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; +__PACKAGE__->meta->initialize; + +__PACKAGE__->configure_acts_as_list(group_by => [qw(module)]); + +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The name is missing.') if !$self->name; + push @errors, $::locale->text('The description is missing.') if !$self->description; + push @errors, $::locale->text('The type is missing.') if !$self->type; + push @errors, $::locale->text('The option field is empty.') if (($self->type || '') eq 'select') && !$self->options; + + return @errors; +} + +use constant OPTION_DEFAULTS => + { + MAXLENGTH => 75, + WIDTH => 30, + HEIGHT => 5, + }; + +sub processed_options { + my ($self) = @_; + + if( exists($self->{processed_options_cache}) ) { + return $self->{processed_options_cache}; + } + + my $ops = $self->options; + my $ret; + + if ( $self->type eq 'select' ) { + my @op_array = split('##', $ops); + $ret = \@op_array; + } + else { + $ret = {%{$self->OPTION_DEFAULTS}}; + while ( $ops =~ /\s*([^=\s]+)\s*=\s*([^\s]*)(?:\s*|$)/g ) { + $ret->{$1} = $2; + } + } + + $self->{processed_options_cache} = $ret; + + return $ret; +} + +sub processed_flags { + my ($self) = @_; + + if( exists($self->{processed_flags_cache}) ) { + return $self->{processed_flags_cache}; + } + + my $flags = $self->flags; + my $ret; + + foreach my $flag (split m/:/, $flags) { + if ( $flag =~ m/(.*?)=(.*)/ ) { + $ret->{$1} = $2; + } else { + $ret->{$flag} = 1; + } + } + + $self->{processed_flags_cache} = $ret; + + return $ret; +} + +sub has_flag { + my ($self, $flag) = @_; + + return $self->processed_flags()->{$flag}; +} 1;