X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=SL%2FClipboard%2FRequirementSpecItem.pm;fp=SL%2FClipboard%2FRequirementSpecItem.pm;h=85bd5d96778ef6d4deb5596f4fe8f7728deb46fe;hp=0000000000000000000000000000000000000000;hb=bd25baf67d259c1b805951dfd92a310766c13661;hpb=51eca07c805710334a326a2eac6df7ba5bdc8aec diff --git a/SL/Clipboard/RequirementSpecItem.pm b/SL/Clipboard/RequirementSpecItem.pm new file mode 100644 index 000000000..85bd5d967 --- /dev/null +++ b/SL/Clipboard/RequirementSpecItem.pm @@ -0,0 +1,101 @@ +package SL::Clipboard::RequirementSpecItem; + +use strict; + +use parent qw(SL::Clipboard::Base); + +use List::Util qw(sum); + +use SL::Common; +use SL::Locale::String; + +sub dump { + my ($self, $object) = @_; + + return $self->as_tree(_load_children($self->reload_object($object)), exclude => sub { ref($_[0]) !~ m/::RequirementSpecItem$/ }); +} + +sub describe { + my ($self) = @_; + + my $item = $self->content; + my $num_children = @{ $item->{children} || [] }; + my $num_grandchildren = sum map { scalar(@{ $_->{children} || [] }) } @{ $item->{children} || [] }; + + if ($item->{item_type} eq 'section') { + return t8('Requirement spec section #1 "#2" with #3 function blocks and a total of #4 sub function blocks; preamble: "#5"', + $item->{fb_number}, $item->{title}, $num_children, $num_grandchildren, Common::truncate($item->{description}, strip => 'full')); + } elsif ($item->{item_type} eq 'function-block') { + return t8('Requirement spec function block #1 with #2 sub function blocks; description: "#3"', + $item->{fb_number}, $num_children, Common::truncate($item->{description}, strip => 'full')); + } else { + return t8('Requirement spec sub function block #1; description: "#2"', + $item->{fb_number}, Common::truncate($item->{description}, strip => 'full')); + } +} + +sub _load_children { + my ($object) = @_; + + _load_children($_) for @{ $object->children }; + + return $object; +} + +sub _fix_object { + my ($self, $object) = @_; + + $object->$_(undef) for qw(fb_number); + $self->_fix_object($_) for @{ $object->children || [] }; +} + +sub _fix_tree { + my ($self, $tree, $object) = @_; + + delete @{ $tree }{ qw(id itime mtime parent_id position requirement_spec_id) }; + $self->_fix_tree($_) for @{ $tree->{children} || [] }; +} + +1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::Clipboard::RequirementSpecItem - Clipboard specialization for +SL::DB::RequirementSpecItem + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns a human-readable description depending on the copied type +(section, function block or sub function block). + +=item C + +This specialization reloads C<$object> from the database, loads all of +its children (but only the other requirement spec items, no other +relationships) and dumps it. + +=item C<_fix_object $object> + +Fixes C<$object> and all of its children by clearing certain columns +like the position or function block numbers. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut