X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FHelper%2FLinkedRecords.pm;h=c7de25b743c66a5454954db8e063054fb58578a7;hb=c7241bf7c547d63999898dee7b5dd486e4d122d3;hp=b75597abb0881ed30b25b4f36429ff832cc2a8bb;hpb=4f7837d76dff9243196ac8fb3c4099215e32c514;p=kivitendo-erp.git diff --git a/SL/DB/Helper/LinkedRecords.pm b/SL/DB/Helper/LinkedRecords.pm index b75597abb..c7de25b74 100644 --- a/SL/DB/Helper/LinkedRecords.pm +++ b/SL/DB/Helper/LinkedRecords.pm @@ -148,14 +148,20 @@ sub _linked_records_implementation { ORDER BY ${wanted}_table, ${wanted}_id, depth ASC; my $links = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $self->id, $self->meta->table); + + return [] unless @$links; + my $link_objs = SL::DB::Manager::RecordLink->get_all(query => [ id => [ map { $_->{id} } @$links ] ]); my @objects = map { $get_objects->($_) } @$link_objs; if ($params{save_path}) { my %links_by_id = map { $_->{id} => $_ } @$links; for (@objects) { - $_->{_record_link_path} = $links_by_id{$_->{_record_link}->id}->{path}; - $_->{_record_link_depth} = $links_by_id{$_->{_record_link}->id}->{depth}; + my $link = $links_by_id{$_->{_record_link}->id}; + my $intermediate_links = SL::DB::Manager::RecordLink->get_all(query => [ id => $link->{path} ]); + $_->{_record_link_path} = $link->{path}; + $_->{_record_link_obj_path} = [ map { $get_objects->($_) } @$intermediate_links ]; + $_->{_record_link_depth} = $link->{depth}; } } @@ -201,6 +207,7 @@ sub sort_linked_records { 'SL::DB::Invoice' => sub { $_[0]->invnumber }, 'SL::DB::PurchaseInvoice' => sub { $_[0]->invnumber }, 'SL::DB::RequirementSpec' => sub { $_[0]->id }, + 'SL::DB::Letter' => sub { $_[0]->letternumber }, UNKNOWN => '9999999999999999', ); my $number_xtor = sub { @@ -228,6 +235,8 @@ sub sort_linked_records { purchase_order => 130, purchase_delivery_order => 140, 'SL::DB::PurchaseInvoice' => 150, + 'SL::DB::PurchaseInvoice' => 150, + 'SL::DB::Letter' => 200, UNKNOWN => 999, ); my $score_xtor = sub { @@ -364,7 +373,7 @@ names in an array reference in which case all links matching any of the model names will be returned. If no parameter C is given, but any of C, C or C, -then C is infered accordingly. If neither are given, C is +then C is inferred accordingly. If neither are given, C is set to C. The optional parameter C can be used to retrieve all documents that may @@ -378,7 +387,7 @@ array reference. Examples: If you only need invoices created directly from an order C<$order> (no -delivery orders inbetween) then the call could look like this: +delivery orders in between) then the call could look like this: my $invoices = $order->linked_records( direction => 'to', @@ -386,7 +395,7 @@ delivery orders inbetween) then the call could look like this: ); Retrieving all invoices from a quotation no matter whether or not -orders or delivery orders where created: +orders or delivery orders were created: my $invoices = $quotation->linked_records( direction => 'to', @@ -429,7 +438,7 @@ visited twice, so this will find the path o1 -> o2 -> do -> o2 -> i without considering it a cycle. -The optional extra flag C will give you extra inforamtion saved in +The optional extra flag C will give you extra information saved in the returned objects: my $records = $order->linked_records( @@ -444,8 +453,8 @@ Every record will have two fields set: =item C<_record_link_path> -And array with the ids of the visited links. The shortest paths will be -prefered, so in the previous example this would contain the ids of o1-o2 and +An array with the ids of the visited links. The shortest paths will be +preferred, so in the previous example this would contain the ids of o1-o2 and o2-i. =item C<_record_link_depth> @@ -537,7 +546,7 @@ Note: If the latter has a default setting it will always mask the creation time. Returns an array reference. -Can only be called both as a class function since it is noe exported. +Can only be called both as a class function since it is not exported. =back