1 package SL::DB::Manager::Unit;
 
   5 use SL::DB::Helper::Manager;
 
   6 use base qw(SL::DB::Helper::Manager);
 
   8 use SL::DB::Helper::Sorted;
 
   9 use SL::DB::Helper::Filtered;
 
  11 use List::Util qw(first);
 
  13 sub object_class { 'SL::DB::Unit' }
 
  15 __PACKAGE__->make_manager_methods;
 
  16 __PACKAGE__->add_filter_specs(
 
  17   convertible_to => sub {
 
  18     my ($key, $value, $prefix) = @_;
 
  19     return __PACKAGE__->convertible_to_filter($key, $value, $prefix);
 
  24   return ( default => [ 'sortkey', 1 ],
 
  25            columns => { SIMPLE => 'ALL',
 
  26                         name   => 'lower(name)',
 
  30 sub convertible_to_filter {
 
  31   my ($class, $key, $unit_name, $prefix) = @_;
 
  33   return () unless $unit_name;
 
  37   my $unit = $class->find_by(name => $unit_name);
 
  39     $::lxdebug->warn("Unit manager: No unit with name $unit_name");
 
  43   return ("${prefix}name" => [ map { $_->name } @{ $unit->convertible_units } ]);
 
  48   $::request->cache('all_units')->{sorted} //= $class->get_all_sorted;
 
  54   return $::request->cache('unit_manager')->{h_unit} //= first { $_->name =~ m{^(?: Std | h | Stunde )$}x } @{ $class->all_units };
 
  57 sub time_based_units {
 
  60   my $h_unit = $class->find_h_unit;
 
  61   return [] if !$h_unit;
 
  62   return $::request->cache('unit_manager')->{units} //= $h_unit->convertible_units;