1 package SL::DB::RequirementSpecItem;
5 use SL::DB::MetaSetup::RequirementSpecItem;
6 use SL::DB::Manager::RequirementSpecItem;
7 use SL::DB::Helper::ActsAsList;
8 use SL::DB::Helper::AttrDuration;
10 __PACKAGE__->meta->add_relationship(
12 type => 'one to many',
13 class => 'SL::DB::RequirementSpecItem',
14 column_map => { id => 'parent_id' },
17 map_class => 'SL::DB::RequirementSpecDependency',
18 map_from => 'depending_item',
19 map_to => 'depended_item',
20 type => 'many to many',
23 map_class => 'SL::DB::RequirementSpecDependency',
24 map_from => 'depended_item',
25 map_to => 'depending_item',
26 type => 'many to many',
30 __PACKAGE__->meta->initialize;
32 __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]);
33 __PACKAGE__->attr_duration(qw(time_estimation));
35 __PACKAGE__->before_delete(\&_before_delete_delete_children);
37 sub _before_delete_delete_children {
40 foreach my $child (@{ SL::DB::Manager::RequirementSpecItem->get_all(where => [ parent_id => $self->id ]) }) {
41 my $result = $child->delete;
42 return $result if !$result;
52 push @errors, t8('The title is missing.') if !$self->parent_id && !$self->title;
60 return [ sort { $a->position <=> $b->position } @{ $self->children } ];
66 $self = $self->parent while $self->parent_id;
74 return 'section' if !$self->parent_id;
75 return $self->parent->parent_id ? 'sub-function-block' : 'function-block';