Revision 7f8599c0
Von Moritz Bunkus vor fast 12 Jahren hinzugefügt
SL/DB/Project.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use List::MoreUtils qw(any); |
|
6 |
|
|
5 | 7 |
use SL::DB::MetaSetup::Project; |
8 |
use SL::DB::Manager::Project; |
|
6 | 9 |
|
7 | 10 |
use SL::DB::Helper::CustomVariables( |
8 | 11 |
module => 'Project', |
9 | 12 |
cvars_alias => 1, |
10 | 13 |
); |
11 | 14 |
|
12 |
__PACKAGE__->meta->make_manager_class; |
|
13 | 15 |
__PACKAGE__->meta->initialize; |
14 | 16 |
|
17 |
sub validate { |
|
18 |
my ($self) = @_; |
|
19 |
|
|
20 |
my @errors; |
|
21 |
push @errors, $::locale->text('The project number is missing.') if !$self->projectnumber; |
|
22 |
push @errors, $::locale->text('The project number is already in use.') if !$self->is_projectnumber_unique; |
|
23 |
push @errors, $::locale->text('The description is missing.') if !$self->description; |
|
24 |
|
|
25 |
return @errors; |
|
26 |
} |
|
27 |
|
|
28 |
sub is_used { |
|
29 |
my ($self) = @_; |
|
30 |
|
|
31 |
# Unsaved projects are never referenced. |
|
32 |
return 0 unless $self->id; |
|
33 |
|
|
34 |
return any { |
|
35 |
my $column = $SL::DB::Manager::Project::project_id_column_prefixes{$_} . 'project_id'; |
|
36 |
$self->db->dbh->selectrow_arrayref(qq|SELECT EXISTS(SELECT * FROM ${_} WHERE ${column} = ?)|, undef, $self->id)->[0] |
|
37 |
} @SL::DB::Manager::Project::tables_with_project_id_cols; |
|
38 |
} |
|
39 |
|
|
40 |
sub is_projectnumber_unique { |
|
41 |
my ($self) = @_; |
|
42 |
|
|
43 |
return 1 unless $self->projectnumber; |
|
44 |
|
|
45 |
my @filter = (projectnumber => $self->projectnumber); |
|
46 |
@filter = (and => [ @filter, '!id' => $self->id ]) if $self->id; |
|
47 |
|
|
48 |
return !SL::DB::Manager::Project->get_first(where => \@filter); |
|
49 |
} |
|
50 |
|
|
15 | 51 |
1; |
16 | 52 |
|
17 | 53 |
__END__ |
... | ... | |
28 | 64 |
|
29 | 65 |
=head1 FUNCTIONS |
30 | 66 |
|
31 |
None so far. |
|
67 |
=over 4 |
|
68 |
|
|
69 |
=item C<validate> |
|
70 |
|
|
71 |
Checks whether or not all fields are set to valid values so that the |
|
72 |
object can be saved. If valid returns an empty list. Returns an array |
|
73 |
of translated error message otherwise. |
|
74 |
|
|
75 |
=item C<is_used> |
|
76 |
|
|
77 |
Checks whether or not the project is referenced from any other |
|
78 |
database table. Returns a boolean value. |
|
79 |
|
|
80 |
=item C<is_projectnumber_unique> |
|
81 |
|
|
82 |
Returns trueish if the project number is not used for any other |
|
83 |
project in the database. Also returns trueish if no project number has |
|
84 |
been set yet. |
|
85 |
|
|
86 |
=back |
|
32 | 87 |
|
33 | 88 |
=head1 AUTHOR |
34 | 89 |
|
Auch abrufbar als: Unified diff
Projektverwaltung auf Rose- und Controller-Code umgestellt