1 package SL::DB::Manager::Project;
5 use parent qw(SL::DB::Helper::Manager);
7 use SL::DB::Helper::Paginated;
8 use SL::DB::Helper::Sorted;
9 use SL::DB::Helper::Filtered;
11 sub object_class { 'SL::DB::Project' }
13 __PACKAGE__->make_manager_methods;
14 __PACKAGE__->add_filter_specs(
16 my ($key, $value, $prefix) = @_;
17 # TODO add boolean context
18 return () if $value eq 'both';
19 return ($prefix . "active" => 1) if $value eq 'active';
20 return (or => [ $prefix . "active" => 0, $prefix . "active" => undef ]) if $value eq 'inactive';
23 my ($key, $value, $prefix) = @_;
24 return () if $value eq 'both';
25 return ($prefix . "valid" => 1) if $value eq 'valid';
26 return (or => [ $prefix . "valid" => 0, $prefix . "valid" => undef ]) if $value eq 'invalid';
29 my ($key, $value, $prefix) = @_;
30 return () if $value eq 'all';
31 return __PACKAGE__->is_not_used_filter($prefix);
35 our %project_id_column_prefixes = (
39 delivery_orders => 'global',
42 our @tables_with_project_id_cols = qw(acc_trans ap ar delivery_order_items delivery_orders invoice oe orderitems);
46 default => [ 'projectnumber', 1 ],
49 customer => 'customer.name',
50 project_type => 'project_type.description',
51 project_status => 'project_status.description',
55 sub is_not_used_filter {
56 my ($class, $prefix) = @_;
58 my $query = join ' UNION ', map {
59 my $column = $project_id_column_prefixes{$_} . 'project_id';
60 qq|SELECT DISTINCT ${column} FROM ${_} WHERE ${column} IS NOT NULL|
61 } @tables_with_project_id_cols;
63 return ("!${prefix}id" => [ \"(${query})" ]);
66 sub default_objects_per_page {
79 SL::DB::Manager::Project - Manager for models for the 'project' table
83 This is a standard Rose::DB::Manager based model manager and can be
90 =item C<is_not_used_filter>
92 Returns an array containing a partial filter suitable for the C<query>
93 parameter that limits to projects that are not referenced from any
104 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>