kivitendo/SL/DB/CustomVariableConfig.pm @ 79b7fc43
4fd22b56 | Sven Schöling | # This file has been auto-generated only because it didn't exist.
|
||
# Feel free to modify it at will; it will not be overwritten automatically.
|
||||
package SL::DB::CustomVariableConfig;
|
||||
use strict;
|
||||
def4a030 | Moritz Bunkus | use List::MoreUtils qw(any);
|
||
4fd22b56 | Sven Schöling | use SL::DB::MetaSetup::CustomVariableConfig;
|
||
2737667a | Moritz Bunkus | use SL::DB::Manager::CustomVariableConfig;
|
||
117fefac | Moritz Bunkus | use SL::DB::Helper::ActsAsList;
|
||
4fd22b56 | Sven Schöling | |||
36703a86 | Bernd Bleßmann | __PACKAGE__->meta->add_relationship(
|
||
partsgroups => {
|
||||
type => 'many to many',
|
||||
map_class => 'SL::DB::CustomVariableConfigPartsgroup',
|
||||
},
|
||||
);
|
||||
2d7e4203 | Sven Schöling | __PACKAGE__->meta->initialize;
|
||
2737667a | Moritz Bunkus | __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;
|
||||
}
|
||||
4fd22b56 | Sven Schöling | |||
5b1e6c5a | Thomas Heck | 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};
|
||||
}
|
||||
0b6c6d4a | Sven Schöling | sub type_dependent_default_value {
|
||
def4a030 | Moritz Bunkus | my ($self) = @_;
|
||
return $self->default_value if $self->type ne 'select';
|
||||
return (any { $_ eq $self->default_value } @{ $self->processed_options }) ? $self->default_value : $self->processed_options->[0];
|
||||
}
|
||||
8e405005 | Moritz Bunkus | sub value_col {
|
||
my ($self) = @_;
|
||||
my $type = $self->type;
|
||||
return {
|
||||
bool => 'bool_value',
|
||||
timestamp => 'timestamp_value',
|
||||
230c9dcf | Moritz Bunkus | date => 'timestamp_value',
|
||
8e405005 | Moritz Bunkus | number => 'number_value',
|
||
integer => 'number_value',
|
||||
customer => 'number_value',
|
||||
vendor => 'number_value',
|
||||
part => 'number_value',
|
||||
text => 'text_value',
|
||||
textfield => 'text_value',
|
||||
select => 'text_value'
|
||||
}->{$type};
|
||||
}
|
||||
4fd22b56 | Sven Schöling | 1;
|