From aa230dee720a3e20e4da6db79b34da415177bf25 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Wed, 14 Nov 2012 12:10:44 +0100 Subject: [PATCH] Bug 9072: Add sort order option to Linker --- C4/Heading.pm | 11 +++++++---- C4/Linker/Default.pm | 13 +++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/C4/Heading.pm b/C4/Heading.pm index dca4d1b..4872a87 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -151,7 +151,8 @@ SearchAuthorities will return only authids. sub authorities { my $self = shift; my $skipmetadata = shift; - my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata ); + my $sortorder = shift; + my ( $results, $total ) = _search( $self, 'match-heading', $skipmetadata, $sortorder ); return $results; } @@ -166,8 +167,9 @@ that are a preferred form of the heading. sub preferred_authorities { my $self = shift; - my $skipmetadata = shift || undef; - my ( $results, $total ) = _search( 'see-from', $skipmetadata ); + my $skipmetadata = shift; + my $sortorder = shift; + my ( $results, $total ) = _search( 'see-from', $skipmetadata, $sortorder ); return $results; } @@ -181,6 +183,7 @@ sub _search { my $self = shift; my $index = shift || undef; my $skipmetadata = shift || undef; + my $sortorder = shift || 'AuthidAsc'; my @marclist; my @and_or; my @excluding = []; @@ -205,7 +208,7 @@ sub _search { return C4::AuthoritiesMarc::SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value, 0, 20, $self->{'auth_type'}, - 'AuthidAsc', $skipmetadata + $sortorder, $skipmetadata ); } diff --git a/C4/Linker/Default.pm b/C4/Linker/Default.pm index 445b408..bc1583d 100644 --- a/C4/Linker/Default.pm +++ b/C4/Linker/Default.pm @@ -39,8 +39,17 @@ sub get_link { } else { - # look for matching authorities - my $authorities = $heading->authorities(1); # $skipmetadata = true + # results sort order (defined in LinkerOptions) + my $sortorder; + foreach (qw( HeadingAsc HeadingDsc AuthidAsc AuthidDsc )) { + if ( $self->{$_} ) { + $sortorder = $_; + last; + } + } + + # look for matching authorities ($skipmetadata = true) + my $authorities = $heading->authorities( 1, $sortorder ); if ( $behavior eq 'default' && $#{$authorities} == 0 ) { $authid = $authorities->[0]->{'authid'}; -- 1.7.9.5