X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRecordLinks.pm;h=d421714157e085920695c4bef4e371131332fc3c;hb=c184bce36ecd18049541dccaaa38d212fb6170cf;hp=eae903e316b929ecc6910b95a409c8aae66b3003;hpb=5df2b57a097f66f6cecba0aa577c7aaba3422ab6;p=kivitendo-erp.git diff --git a/SL/RecordLinks.pm b/SL/RecordLinks.pm index eae903e31..d42171415 100644 --- a/SL/RecordLinks.pm +++ b/SL/RecordLinks.pm @@ -9,9 +9,39 @@ sub create_links { my $self = shift; my %params = @_; - Common::check_params(\%params, qw(links)); + if ($params{mode} && ($params{mode} eq 'ids')) { + Common::check_params_x(\%params, [ qw(from_ids to_ids) ]); - if (!scalar @{ $params{links} }) { + } else { + Common::check_params(\%params, qw(links)); + + } + + my @links; + + if ($params{mode} && ($params{mode} eq 'ids')) { + my ($from_to, $to_from) = $params{from_ids} ? qw(from to) : qw(to from); + my %ids; + + if ('ARRAY' eq ref $params{"${from_to}_ids"}) { + $ids{$from_to} = $params{"${from_to}_ids"}; + } else { + $ids{$from_to} = [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ]; + } + + if (my $num = scalar @{ $ids{$from_to} }) { + $ids{$to_from} = [ ($params{"${to_from}_id"}) x $num ]; + @links = map { { 'from_table' => $params{from_table}, + 'from_id' => $ids{from}->[$_], + 'to_table' => $params{to_table}, + 'to_id' => $ids{to}->[$_], } } (0 .. $num - 1); + } + + } else { + @links = @{ $params{links} }; + } + + if (!scalar @links) { $main::lxdebug->leave_sub(); return; } @@ -24,7 +54,7 @@ sub create_links { my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|; my $sth = prepare_query($form, $dbh, $query); - foreach my $link (@{ $params{links} }) { + foreach my $link (@links) { next if ('HASH' ne ref $link); next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});