Revision 37ff0a6b
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/DB/CustomVariable.pm | ||
---|---|---|
11 | 11 |
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. |
12 | 12 |
__PACKAGE__->meta->make_manager_class; |
13 | 13 |
|
14 |
sub unparsed_value { |
|
15 |
my ($self, $new) = @_; |
|
16 |
|
|
17 |
$self->{__unparsed_value} = $new; |
|
18 |
} |
|
19 |
|
|
20 |
sub _ensure_config { |
|
21 |
my ($self) = @_; |
|
22 |
|
|
23 |
return $self->config if $self->config; |
|
24 |
return undef if !defined $self->config_id; |
|
25 |
$self->config( SL::DB::CustomVariableConfig->new(id => $self->config_id)->load ); |
|
26 |
} |
|
27 |
|
|
28 |
sub parse_value { |
|
29 |
my ($self) = @_; |
|
30 |
my $type = $self->_ensure_config->type; |
|
31 |
|
|
32 |
return unless exists $self->{__unparsed_value}; |
|
33 |
|
|
34 |
my $unparsed = delete $self->{__unparsed_value}; |
|
35 |
|
|
36 |
if ($type =~ m{^(?:customer|vendor|part|bool|number)}) { |
|
37 |
return $self->number_value(defined($unparsed) ? $unparsed * 1 : undef); |
|
38 |
} |
|
39 |
|
|
40 |
if ($type =~ m{^(?:date|timestamp)}) { |
|
41 |
return $self->timestamp_value(defined($unparsed) ? DateTime->from_kivi($unparsed) : undef); |
|
42 |
} |
|
43 |
|
|
44 |
# text, textfield, select |
|
45 |
$self->text_value($unparsed); |
|
46 |
} |
|
47 |
|
|
14 | 48 |
sub value { |
15 | 49 |
my $self = $_[0]; |
16 |
my $type = $self->config->type; |
|
50 |
my $type = $self->_ensure_config->type; |
|
51 |
|
|
52 |
if (scalar(@_) > 1) { |
|
53 |
$self->unparsed_value($_[1]); |
|
54 |
$self->parse_value; |
|
55 |
} |
|
17 | 56 |
|
18 | 57 |
goto &bool_value if $type eq 'bool'; |
19 | 58 |
goto ×tamp_value if $type eq 'timestamp'; |
20 | 59 |
goto &number_value if $type eq 'number'; |
21 | 60 |
|
22 |
if ( $_[1] && ($type eq 'customer' || $type eq 'vendor' || $type eq 'part') ) { |
|
23 |
$self->number_value($_[1]); |
|
24 |
} |
|
25 |
|
|
26 | 61 |
if ( $type eq 'customer' ) { |
27 | 62 |
require SL::DB::Customer; |
28 | 63 |
|
Auch abrufbar als: Unified diff
CustomVariables: Verwendung mit RDBO als Writer implementiert