X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRecordLinks.pm;h=77086ba70660aedf1d87f285467174cbd77d931a;hb=4bd1e2f8b588972f10f92728301feacefd5ee4dd;hp=6229cfe43389dcb1bdfefa8f053973e780148b45;hpb=1f6662b40914cbca0506545f3f2ccfa71c32b0c7;p=kivitendo-erp.git diff --git a/SL/RecordLinks.pm b/SL/RecordLinks.pm index 6229cfe43..77086ba70 100644 --- a/SL/RecordLinks.pm +++ b/SL/RecordLinks.pm @@ -1,5 +1,8 @@ package RecordLinks; +use utf8; +use strict; + use SL::Common; use SL::DBUtils; use Data::Dumper; @@ -170,4 +173,109 @@ sub get_links_via { return wantarray ? @{ $result } : $result; } +sub delete { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]); + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + # content + my (@where_tokens, @where_values); + + for my $col (qw(from_table from_id to_table to_id)) { + add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col}; + } + + my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : ''; + my $query = "DELETE FROM record_links $where"; + + do_query($form, $dbh, $query, @where_values); + + $dbh->commit() unless ($params{dbh}); + + $main::lxdebug->leave_sub(); +} + 1; + +__END__ + +=head1 NAME + +SL::RecordLinks - Verlinkung von kivitendo Objekten. + +=head1 SYNOPSIS + + use SL::RecordLinks; + + my @links = RecordLinks->get_links( + from_table => 'ar', + from_id => 2, + to_table => 'oe', + ); + my @links = RecordLinks->get_links_via( + from_table => 'oe', + to_id => '14', + via => [ + { id => 12 }, + { id => 13}, + ], + ); + + RecordLinks->create_links( + mode => 'ids', + from_table => 'ar', + from_id => 1, + to_table => 'oe', + to_ids => [4, 6, 9], + ) + RecordLinks->create_links(@links); + + delete + +=head1 DESCRIPTION + +Transitive RecordLinks mit get_links_via. + +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 + +=cut