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 ne 'orphaned';
31 return __PACKAGE__->is_not_used_filter($prefix);
34 my ($key, $value, $prefix) = @_;
35 return or => [ map { $prefix . $_ => $value } qw(projectnumber description customer.name) ]
39 our %project_id_column_prefixes = (
43 delivery_orders => 'global',
46 our @tables_with_project_id_cols = qw(acc_trans ap ar delivery_order_items delivery_orders invoice oe orderitems);
50 default => [ 'projectnumber', 1 ],
53 customer => 'customer.name',
54 project_type => 'project_type.description',
55 project_status => 'project_status.description',
56 customer_and_description => [ qw(customer.name project.description) ],
60 sub is_not_used_filter {
61 my ($class, $prefix) = @_;
63 my $query = join ' UNION ', map {
64 my $column = $project_id_column_prefixes{$_} . 'project_id';
65 qq|SELECT DISTINCT ${column} FROM ${_} WHERE ${column} IS NOT NULL|
66 } @tables_with_project_id_cols;
68 return ("!${prefix}id" => [ \"(${query})" ]);
71 sub default_objects_per_page {
84 SL::DB::Manager::Project - Manager for models for the 'project' table
88 This is a standard Rose::DB::Manager based model manager and can be
95 =item C<is_not_used_filter>
97 Returns an array containing a partial filter suitable for the C<query>
98 parameter that limits to projects that are not referenced from any
109 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>