+use SL::DB::Manager::Project;
+
+use SL::DB::Helper::CustomVariables(
+ module => 'Projects',
+ cvars_alias => 1,
+);
+
+__PACKAGE__->meta->initialize;
+
+sub validate {
+ my ($self) = @_;
+
+ my @errors;
+ push @errors, $::locale->text('The project number is missing.') if !$self->projectnumber;
+ push @errors, $::locale->text('The project number is already in use.') if !$self->is_projectnumber_unique;
+ push @errors, $::locale->text('The description is missing.') if !$self->description;
+
+ return @errors;
+}
+
+sub is_used {
+ my ($self) = @_;
+
+ # Unsaved projects are never referenced.
+ return 0 unless $self->id;
+
+ return any {
+ my $column = $SL::DB::Manager::Project::project_id_column_prefixes{$_} . 'project_id';
+ $self->db->dbh->selectrow_arrayref(qq|SELECT EXISTS(SELECT * FROM ${_} WHERE ${column} = ?)|, undef, $self->id)->[0]
+ } @SL::DB::Manager::Project::tables_with_project_id_cols;
+}
+
+sub is_projectnumber_unique {
+ my ($self) = @_;