Refactoring
[kivitendo-erp.git] / SL / DB / RequirementSpecTextBlock.pm
1 package SL::DB::RequirementSpecTextBlock;
2
3 use strict;
4
5 use List::MoreUtils qw(any);
6 use Rose::DB::Object::Helpers;
7 use Rose::DB::Object::Util;
8
9 use SL::DB::MetaSetup::RequirementSpecTextBlock;
10 use SL::DB::Manager::RequirementSpecTextBlock;
11 use SL::DB::Helper::ActsAsList;
12 use SL::Locale::String;
13
14 __PACKAGE__->meta->initialize;
15
16 __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id output_position)]);
17
18 __PACKAGE__->before_save(\  &_before_save_invalidate_requirement_spec_version);
19 __PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
20
21 sub validate {
22   my ($self) = @_;
23
24   my @errors;
25   push @errors, t8('The title is missing.') if !$self->title;
26
27   return @errors;
28 }
29
30 sub _before_save_invalidate_requirement_spec_version {
31   my ($self, %params) = @_;
32
33
34   return 1 if !$self->requirement_spec_id;
35
36   my %changed_columns = map { $_ => 1 } (Rose::DB::Object::Helpers::dirty_columns($self));
37
38   $self->requirement_spec->invalidate_version
39     if !Rose::DB::Object::Util::is_in_db($self) || any { $changed_columns{$_} } qw(title text position output_position);
40
41   return 1;
42 }
43
44 sub _before_delete_invalidate_requirement_spec_version {
45   my ($self, %params) = @_;
46
47   $self->requirement_spec->invalidate_version if $self->requirement_spec_id;
48
49   return 1;
50 }
51
52 1;