1 package SL::DB::RequirementSpecTextBlock;
6 use List::MoreUtils qw(any);
7 use Rose::DB::Object::Helpers;
8 use Rose::DB::Object::Util;
11 use SL::DB::MetaSetup::RequirementSpecTextBlock;
12 use SL::DB::Manager::RequirementSpecTextBlock;
13 use SL::DB::Helper::ActsAsList;
14 use SL::DB::Helper::AttrHTML;
15 use SL::Locale::String;
17 __PACKAGE__->meta->add_relationship(
19 type => 'one to many',
20 class => 'SL::DB::RequirementSpecPicture',
21 column_map => { id => 'text_block_id' },
25 __PACKAGE__->meta->initialize;
27 __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id output_position)]);
28 __PACKAGE__->attr_html('text');
30 __PACKAGE__->before_save(\ &_before_save_invalidate_requirement_spec_version);
31 __PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
37 push @errors, t8('The title is missing.') if !$self->title;
42 sub _before_save_invalidate_requirement_spec_version {
43 my ($self, %params) = @_;
45 return 1 if !$self->requirement_spec_id || $self->requirement_spec->working_copy_id;
47 my %changed_columns = map { $_ => 1 } (Rose::DB::Object::Helpers::dirty_columns($self));
49 $self->requirement_spec->invalidate_version
50 if !Rose::DB::Object::Util::is_in_db($self) || any { $changed_columns{$_} } qw(title text position output_position);
55 sub _before_delete_invalidate_requirement_spec_version {
56 my ($self, %params) = @_;
58 $self->requirement_spec->invalidate_version if $self->requirement_spec_id;
64 my ($self, @args) = @_;
66 croak "Not a writer" if @args;
68 return [ sort { $a->position <=> $b->position } $self->pictures ];
74 return Common::truncate($self->text_as_stripped_html // '', at => 200);