Revision 2524843b
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/InstanceConfiguration.pm | ||
---|---|---|
7 | 7 |
|
8 | 8 |
use parent qw(Rose::Object); |
9 | 9 |
use Rose::Object::MakeMethods::Generic ( |
10 |
'scalar --get_set_init' => [ qw(data currencies) ], |
|
10 |
'scalar --get_set_init' => [ qw(data currencies default_currency _table_currencies_exists) ],
|
|
11 | 11 |
); |
12 | 12 |
|
13 | 13 |
sub init_data { |
14 | 14 |
return {} if !$::auth->client; |
15 |
return SL::DBUtils::selectfirst_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT * FROM defaults|); |
|
16 |
} |
|
15 | 17 |
|
16 |
my $dbh = $::form->get_standard_dbh; |
|
17 |
my $data = SL::DBUtils::selectfirst_hashref_query($::form, $dbh, qq|SELECT * FROM defaults|); |
|
18 |
$data->{default_currency} = (SL::DBUtils::selectfirst_array_query($::form, $dbh, qq|SELECT name FROM currencies WHERE id = ?|, $data->{currency_id}))[0] if $data->{currency_id}; |
|
19 |
|
|
20 |
return $data; |
|
18 |
sub init__table_currencies_exists { |
|
19 |
return 0 if !$::auth->client; |
|
20 |
return !!(SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT tablename FROM pg_tables WHERE (schemaname = 'public') AND (tablename = 'currencies')|))[0]; |
|
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
sub init_currencies { |
24 |
return [] if !$::auth->client; |
|
24 |
my ($self) = @_; |
|
25 |
|
|
26 |
return [] if !$self->_table_currencies_exists; |
|
25 | 27 |
return [ map { $_->{name} } SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT name FROM currencies ORDER BY id ASC|) ]; |
26 | 28 |
} |
27 | 29 |
|
30 |
sub init_default_currency { |
|
31 |
my ($self) = @_; |
|
32 |
|
|
33 |
return undef if !$self->_table_currencies_exists || !$self->data->{currency_id}; |
|
34 |
return (SL::DBUtils::selectfirst_array_query($::form, $::form->get_standard_dbh, qq|SELECT name FROM currencies WHERE id = ?|, $self->data->{currency_id}))[0]; |
|
35 |
} |
|
36 |
|
|
28 | 37 |
sub reload { |
29 |
my ($self) = @_; |
|
30 |
$self->{data} = $self->init_data; |
|
31 |
$self->{currencies} = $self->init_currencies; |
|
38 |
my ($self) = @_; |
|
39 |
|
|
40 |
delete @{ $self }{qw(data currencies default_currency)}; |
|
41 |
|
|
32 | 42 |
return $self; |
33 | 43 |
} |
34 | 44 |
|
Auch abrufbar als: Unified diff
InstanceConfiguration: currencies und default_currency nur auf Bedarf auslesen