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.
 
   4 package SL::DB::CustomVariableConfig;
 
   8 use List::MoreUtils qw(any);
 
  10 use SL::DB::MetaSetup::CustomVariableConfig;
 
  11 use SL::DB::Manager::CustomVariableConfig;
 
  12 use SL::DB::Helper::ActsAsList;
 
  14 __PACKAGE__->meta->add_relationship(
 
  16     type       => 'many to many',
 
  17     map_class  => 'SL::DB::CustomVariableConfigPartsgroup',
 
  21 __PACKAGE__->meta->initialize;
 
  23 __PACKAGE__->configure_acts_as_list(group_by => [qw(module)]);
 
  29   push @errors, $::locale->text('The name is missing.')        if !$self->name;
 
  30   push @errors, $::locale->text('The description is missing.') if !$self->description;
 
  31   push @errors, $::locale->text('The type is missing.')        if !$self->type;
 
  32   push @errors, $::locale->text('The option field is empty.')  if (($self->type || '') eq 'select') && !$self->options;
 
  37 use constant OPTION_DEFAULTS =>
 
  44 sub processed_options {
 
  47   if( exists($self->{processed_options_cache}) ) {
 
  48     return $self->{processed_options_cache};
 
  51   my $ops = $self->options;
 
  54   if ( $self->type eq 'select' ) {
 
  55     my @op_array = split('##', $ops);
 
  59     $ret = {%{$self->OPTION_DEFAULTS}};
 
  60     while ( $ops =~ /\s*([^=\s]+)\s*=\s*([^\s]*)(?:\s*|$)/g ) {
 
  65   $self->{processed_options_cache} = $ret;
 
  73   if( exists($self->{processed_flags_cache}) ) {
 
  74     return $self->{processed_flags_cache};
 
  77   my $flags = $self->flags;
 
  80   foreach my $flag (split m/:/, $flags) {
 
  81     if ( $flag =~ m/(.*?)=(.*)/ ) {
 
  88   $self->{processed_flags_cache} = $ret;
 
  94   my ($self, $flag) = @_;
 
  96   return $self->processed_flags()->{$flag};
 
  99 sub type_dependent_default_value {
 
 102   return $self->default_value if $self->type ne 'select';
 
 103   return (any { $_ eq $self->default_value } @{ $self->processed_options }) ? $self->default_value : $self->processed_options->[0];
 
 109   my $type = $self->type;
 
 112     bool      => 'bool_value',
 
 113     timestamp => 'timestamp_value',
 
 114     date      => 'timestamp_value',
 
 115     number    => 'number_value',
 
 116     integer   => 'number_value',
 
 117     customer  => 'number_value',
 
 118     vendor    => 'number_value',
 
 119     part      => 'number_value',
 
 120     text      => 'text_value',
 
 121     textfield => 'text_value',
 
 122     select    => 'text_value'