From 3af71f2e27419024b28a2ff65e8b4d7cf499035d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 22 Jul 2009 13:43:39 +0200 Subject: [PATCH] Transitive RecordLinks mit get_links_via. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit get_links_via erwartet den zusätzlichen parameter via via ist ein hashref mit den jeweils optionalen einträgen table und id, die sich genauso verhalten wie die from/to_table/id werte der get_links funktion. Alternativ kann via auch ein Array dieser Hashes sein: get_links_via( from_table => 'oe', from_id => 1, to_table => 'ar', via => { table => 'delivery_orders' }, ) get_links_via( from_table => 'oe', to_id => '14', via => [ { id => 12 }, { id => 13}, ], ) Die Einträge in einem via-Array werden exakt in dieser Reihenfolge benutzt und sind nicht optional. Da obige Beispiel würde also die Verknüpfung: oe:11 -> ar:12 -> is:13 -> do:14 finden, nicht aber: oe:11 -> ar:13 -> do:14 --- SL/RecordLinks.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/SL/RecordLinks.pm b/SL/RecordLinks.pm index d42171415..c50499874 100644 --- a/SL/RecordLinks.pm +++ b/SL/RecordLinks.pm @@ -109,4 +109,57 @@ sub get_links { return wantarray ? @{ $links } : $links; } +sub get_links_via { + $main::lxdebug->enter_sub(); + + use SL::MoreCommon; + use Data::Dumper; + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]); + Common::check_params(\%params, "via"); + + my @hops = ref $params{via} eq 'ARRAY' + ? @{ $params{via} } + : $params{via}; + unshift @hops, +{ table => $params{from_table}, id => $params{from_id} }; + push @hops, +{ table => $params{to_table}, id => $params{to_id} }; + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $last_hop = shift @hops; + my @links = undef; + for my $hop (@hops) { + + my @temp_links = $self->get_links( + from_table => $last_hop->{table}, + from_id => $last_hop->{id}, + to_table => $hop->{table}, + to_id => $hop->{id}, + ); + + if (@links) { + @links = grep { $_ } + cross { + if ( $a->{to_table} eq $b->{from_table} + && $a->{to_id} eq $b->{from_id} ) { + +{ $a->{from_table}, $a->{from_id}, + $b->{to_table}, $b->{to_table} } + } + } @links, @temp_links; + } else { + @links = @temp_links; + } + + $last_hop = $hop; + } + + $main::lxdebug->leave_sub(); + + return wantarray ? @links : \@links; +} + 1; -- 2.20.1