X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/880a2e9f233d585d9e1a3d8dc17b2795b8513fcf..df33875fc30c508b60af9421d0061e66cdc0d55a:/SL/DB/Manager/Unit.pm diff --git a/SL/DB/Manager/Unit.pm b/SL/DB/Manager/Unit.pm index 8b3c138a8..f081af49e 100644 --- a/SL/DB/Manager/Unit.pm +++ b/SL/DB/Manager/Unit.pm @@ -6,10 +6,17 @@ use SL::DB::Helper::Manager; use base qw(SL::DB::Helper::Manager); use SL::DB::Helper::Sorted; +use SL::DB::Helper::Filtered; sub object_class { 'SL::DB::Unit' } __PACKAGE__->make_manager_methods; +__PACKAGE__->add_filter_specs( + convertible_to => sub { + my ($key, $value, $prefix) = @_; + return __PACKAGE__->convertible_to_filter($key, $value, $prefix); + }, +); sub _sort_spec { return ( default => [ 'sortkey', 1 ], @@ -18,4 +25,20 @@ sub _sort_spec { }); } +sub convertible_to_filter { + my ($class, $key, $unit_name, $prefix) = @_; + + return () unless $unit_name; + + $prefix //= ''; + + my $unit = $class->find_by(name => $unit_name); + if (!$unit) { + $::lxdebug->warn("Unit manager: No unit with name $unit_name"); + return (); + } + + return ("${prefix}name" => [ map { $_->name } @{ $unit->convertible_units } ]); +} + 1;