kivitendo/SL/DB/RequirementSpec.pm @ c19b1e03
d17e1b9d | Moritz Bunkus | package SL::DB::RequirementSpec;
|
||
use strict;
|
||||
34948207 | Moritz Bunkus | use Carp;
|
||
d17e1b9d | Moritz Bunkus | use SL::DB::MetaSetup::RequirementSpec;
|
||
b2e1809f | Moritz Bunkus | use SL::DB::Manager::RequirementSpec;
|
||
d17e1b9d | Moritz Bunkus | use SL::Locale::String;
|
||
__PACKAGE__->meta->add_relationship(
|
||||
items => {
|
||||
type => 'one to many',
|
||||
class => 'SL::DB::RequirementSpecItem',
|
||||
column_map => { id => 'requirement_spec_id' },
|
||||
},
|
||||
text_blocks => {
|
||||
type => 'one to many',
|
||||
class => 'SL::DB::RequirementSpecTextBlock',
|
||||
column_map => { id => 'requirement_spec_id' },
|
||||
},
|
||||
);
|
||||
__PACKAGE__->meta->initialize;
|
||||
b2e1809f | Moritz Bunkus | __PACKAGE__->before_save('_before_save_initialize_not_null_columns');
|
||
d17e1b9d | Moritz Bunkus | sub validate {
|
||
my ($self) = @_;
|
||||
my @errors;
|
||||
push @errors, t8('The title is missing.') if !$self->title;
|
||||
return @errors;
|
||||
}
|
||||
b2e1809f | Moritz Bunkus | sub _before_save_initialize_not_null_columns {
|
||
my ($self) = @_;
|
||||
$self->previous_section_number(0) if !defined $self->previous_section_number;
|
||||
$self->previous_fb_number(0) if !defined $self->previous_fb_number;
|
||||
return 1;
|
||||
}
|
||||
34948207 | Moritz Bunkus | sub text_blocks_for_position {
|
||
my ($self, $output_position) = @_;
|
||||
return [ sort { $a->position <=> $b->position } grep { $_->output_position == $output_position } @{ $self->text_blocks } ];
|
||||
}
|
||||
sub sections {
|
||||
my ($self, @rest) = @_;
|
||||
croak "This sub is not a writer" if @rest;
|
||||
return [ sort { $a->position <=> $b->position } grep { !$_->parent_id } @{ $self->items } ];
|
||||
}
|
||||
c1569bc1 | Moritz Bunkus | sub displayable_name {
|
||
my ($self) = @_;
|
||||
return sprintf('%s: "%s"', $self->type->description, $self->title);
|
||||
}
|
||||
d17e1b9d | Moritz Bunkus | 1;
|