]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Helper/CustomVariables.pm
CsvImport Waren: Preisupdate auch bei Erzeugnissen u. Dienstleistungen ermöglichen.
[mfinanz.git] / SL / DB / Helper / CustomVariables.pm
index 373a60cf1cb1e6456cb4967c4ee23fb1a691cdc9..6f470357d198eb8bf0f334d6b9c374a05cfd597a 100644 (file)
@@ -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_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 {
 }
 
 sub save_meta_info {
@@ -125,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;
 
 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 {
 }
 
 sub _overload_by_module {
@@ -248,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.
 
 This is a Rose::DB::Object::Relationship accessor, generated for cvars. Use it
 like any other OneToMany relationship.
 
+Note that unlike L</cvars_by_config> 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<cvars [ CUSTOM_VARIABLES ]>
 
 Alias to C<custom_variables>. Will only be installed if C<cvars_alias> was
 =item C<cvars [ CUSTOM_VARIABLES ]>
 
 Alias to C<custom_variables>. Will only be installed if C<cvars_alias> was
@@ -292,6 +314,7 @@ vivified with the same rules as in C<cvars_by_config>.
 
 =head1 AUTHOR
 
 
 =head1 AUTHOR
 
-Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
+Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
+Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
 
 =cut
 
 =cut