epic-ts
[kivitendo-erp.git] / SL / Clipboard / RequirementSpecItem.pm
1 package SL::Clipboard::RequirementSpecItem;
2
3 use strict;
4
5 use parent qw(SL::Clipboard::Base);
6
7 use List::Util qw(sum);
8
9 use SL::Common;
10 use SL::Locale::String;
11
12 sub dump {
13   my ($self, $object) = @_;
14
15   return $self->as_tree(_load_children($self->reload_object($object)), exclude => sub { ref($_[0]) !~ m/::RequirementSpecItem$/ });
16 }
17
18 sub describe {
19   my ($self) = @_;
20
21   my $item              = $self->content;
22   my $num_children      = @{ $item->{children} || [] };
23   my $num_grandchildren = sum map { scalar(@{ $_->{children} || [] }) } @{ $item->{children} || [] };
24
25   if ($item->{item_type} eq 'section') {
26     return t8('Requirement spec section #1 "#2" with #3 function blocks and a total of #4 sub function blocks; preamble: "#5"',
27               $item->{fb_number}, $item->{title}, $num_children, $num_grandchildren, Common::truncate($item->{description}, strip => 'full'));
28   } elsif ($item->{item_type} eq 'function-block') {
29     return t8('Requirement spec function block #1 with #2 sub function blocks; description: "#3"',
30               $item->{fb_number}, $num_children, Common::truncate($item->{description}, strip => 'full'));
31   } else {
32     return t8('Requirement spec sub function block #1; description: "#2"',
33               $item->{fb_number}, Common::truncate($item->{description}, strip => 'full'));
34   }
35 }
36
37 sub _load_children {
38   my ($object) = @_;
39
40   _load_children($_) for @{ $object->children };
41
42   return $object;
43 }
44
45 sub _fix_object {
46   my ($self, $object) = @_;
47
48   $object->$_(undef)     for qw(fb_number);
49   $self->_fix_object($_) for @{ $object->children || [] };
50 }
51
52 sub _fix_tree {
53   my ($self, $tree, $object) = @_;
54
55   delete @{ $tree }{ qw(id itime mtime parent_id position requirement_spec_id) };
56   $self->_fix_tree($_) for @{ $tree->{children} || [] };
57 }
58
59 1;
60 __END__
61
62 =pod
63
64 =encoding utf8
65
66 =head1 NAME
67
68 SL::Clipboard::RequirementSpecItem - Clipboard specialization for
69 SL::DB::RequirementSpecItem
70
71 =head1 FUNCTIONS
72
73 =over 4
74
75 =item C<describe>
76
77 Returns a human-readable description depending on the copied type
78 (section, function block or sub function block).
79
80 =item C<dump $object>
81
82 This specialization reloads C<$object> from the database, loads all of
83 its children (but only the other requirement spec items, no other
84 relationships) and dumps it.
85
86 =item C<_fix_object $object>
87
88 Fixes C<$object> and all of its children by clearing certain columns
89 like the position or function block numbers.
90
91 =back
92
93 =head1 BUGS
94
95 Nothing here yet.
96
97 =head1 AUTHOR
98
99 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
100
101 =cut