From 7861cc07ba8afdf09079c7b51fdb99ad99132688 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 3 May 2018 13:12:19 +0200 Subject: [PATCH] Bug 20702: Bind results of GetHostItemsInfo to the EasyAnalyticalRecords pref Triggered by the finding on bug 20697. The three calls of GetHostItemsInfo should be controlled by the pref. This patch makes the sub return an empty list when the pref is disabled. The patch simplifies the sub by merging the two identical foreach loops depending on the field number in MARC21/UNIMARC. Will add a unit test on a follow-up patch. Test plan: See next patch. Signed-off-by: Marcel de Rooy Signed-off-by: Mark Tompsett Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Items.pm | 62 +++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index e7279ff8a1..bf464c3e30 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1206,44 +1206,40 @@ sub GetItemsLocationInfo { =head2 GetHostItemsInfo - $hostiteminfo = GetHostItemsInfo($hostfield); - Returns the iteminfo for items linked to records via a host field + $hostiteminfo = GetHostItemsInfo($hostfield); + Returns the iteminfo for items linked to records via a host field =cut sub GetHostItemsInfo { - my ($record) = @_; - my @returnitemsInfo; - - if (C4::Context->preference('marcflavour') eq 'MARC21' || - C4::Context->preference('marcflavour') eq 'NORMARC'){ - foreach my $hostfield ( $record->field('773') ) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - my @hostitemInfos = GetItemsInfo($hostbiblionumber); - foreach my $hostitemInfo (@hostitemInfos){ - if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ - push (@returnitemsInfo,$hostitemInfo); - last; - } - } - } - } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC'){ - foreach my $hostfield ( $record->field('461') ) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - my @hostitemInfos = GetItemsInfo($hostbiblionumber); - foreach my $hostitemInfo (@hostitemInfos){ - if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ - push (@returnitemsInfo,$hostitemInfo); - last; - } - } - } - } - return @returnitemsInfo; -} + my ($record) = @_; + my @returnitemsInfo; + if( !C4::Context->preference('EasyAnalyticalRecords') ) { + return @returnitemsInfo; + } + + my @fields; + if( C4::Context->preference('marcflavour') eq 'MARC21' || + C4::Context->preference('marcflavour') eq 'NORMARC') { + @fields = $record->field('773'); + } elsif( C4::Context->preference('marcflavour') eq 'UNIMARC') { + @fields = $record->field('461'); + } + + foreach my $hostfield ( @fields ) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + my @hostitemInfos = GetItemsInfo($hostbiblionumber); + foreach my $hostitemInfo (@hostitemInfos) { + if( $hostitemInfo->{itemnumber} eq $linkeditemnumber ) { + push @returnitemsInfo, $hostitemInfo; + last; + } + } + } + return @returnitemsInfo; +} =head2 GetLastAcquisitions -- 2.39.5