X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/d453cc01303ea4a4a88505f0b98c8ca9fc01141a..cd3150ed14f13bc1af071dd0f91015dd32360eae:/SL/DB/Helper/CustomVariables.pm diff --git a/SL/DB/Helper/CustomVariables.pm b/SL/DB/Helper/CustomVariables.pm index 3c43624db..6f470357d 100644 --- a/SL/DB/Helper/CustomVariables.pm +++ b/SL/DB/Helper/CustomVariables.pm @@ -26,6 +26,7 @@ sub import { make_cvar_alias($caller_package, %params) if $params{cvars_alias}; make_cvar_by_configs($caller_package, %params); make_cvar_by_name($caller_package, %params); + make_cvar_as_hashref($caller_package, %params); } sub save_meta_info { @@ -42,8 +43,11 @@ sub save_meta_info { sub make_cvar_accessor { my ($caller_package, %params) = @_; - my @module_filter = $params{module} ? - ("config_id" => [ \"(SELECT custom_variable_configs.id FROM custom_variable_configs WHERE custom_variable_configs.module = '$params{module}')" ]) : + my $modules = ('ARRAY' eq ref $params{module}) ? + join ',', @{ $params{module} } : + $params{module}; + my @module_filter = $modules ? + ("config_id" => [ \"(SELECT custom_variable_configs.id FROM custom_variable_configs WHERE custom_variable_configs.module IN ( '$modules' ))" ]) : # " make emacs happy (); $caller_package->meta->add_relationships( @@ -122,14 +126,30 @@ sub make_cvar_by_name { } } +sub make_cvar_as_hashref { + my ($caller_package, %params) = @_; + + no strict 'refs'; + *{ $caller_package . '::cvar_as_hashref' } = sub { + my ($self) = @_; + @_ > 1 and croak "not an accessor"; + + my $cvars_by_config = $self->cvars_by_config; + + my %return = map { + $_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid } + } @$cvars_by_config; + + return \%return; + } +} + sub _all_configs { my (%params) = @_; require SL::DB::CustomVariableConfig; - $params{module} - ? SL::DB::Manager::CustomVariableConfig->get_all(query => [ module => $params{module} ]) - : SL::DB::Manager::CustomVariableConfig->get_all; + SL::DB::Manager::CustomVariableConfig->get_all_sorted($params{module} ? (query => [ module => $params{module} ]) : ()); } sub _overload_by_module { @@ -245,6 +265,11 @@ Secondary classes may currently not have cvars of their own. This is a Rose::DB::Object::Relationship accessor, generated for cvars. Use it like any other OneToMany relationship. +Note that unlike L this accessor only returns +variables that have already been created for this object. No variables +will be autovivified for configs for which no variable has been +created yet. + =item C Alias to C. Will only be installed if C was @@ -289,6 +314,7 @@ vivified with the same rules as in C. =head1 AUTHOR -Sven Schöling Es.schoeling@linet-services.deE +Sven Schöling Es.schoeling@linet-services.deE, +Moritz Bunkus Em.bunkus@linet-services.deE =cut