From 7266d50dd2725c87acf889aa7d6a211999ca1c47 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 16 Jan 2019 13:32:35 +0100 Subject: [PATCH] Bug 22140: Use of EasyAnalyticalRecords pref in search Like Bug 20702 defined GetHostItemsInfo does nothing if EasyAnalyticalRecords pref is disabled, there are other places where code must be dependant on this pref. Test plan : 1) Build an analitical record with 773$0 and $9 2) Enable EasyAnalyticalRecords 3) Don't apply patch 4) Go to OPAC 5) Perform a search that displays the record, check there is the linked item 6) Open record detail page, check there is the linked item 7) Apply patch and redo 5) and 6) 8) Disable EasyAnalyticalRecords 9) redo 5) and 6), you should not see the linked item Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- C4/Search.pm | 45 ++++++++++++++++++++++++--------------------- opac/opac-detail.pl | 31 ++++++++++++++++--------------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index fac04b0079..ef81e19e7c 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2008,28 +2008,31 @@ sub searchResults { # Pull out the items fields my @fields = $marcrecord->field($itemtag); my $marcflavor = C4::Context->preference("marcflavour"); + # adding linked items that belong to host records - my $analyticsfield = '773'; - if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { - $analyticsfield = '773'; - } elsif ($marcflavor eq 'UNIMARC') { - $analyticsfield = '461'; - } - foreach my $hostfield ( $marcrecord->field($analyticsfield)) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - if( $hostbiblionumber ) { - my $hostbiblio = GetMarcBiblio({ - biblionumber => $hostbiblionumber, - embed_items => 1 }); - my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); - if( $hostbiblio ) { - my @hostitems = $hostbiblio->field($itemfield); - foreach my $hostitem (@hostitems){ - if ($hostitem->subfield("9") eq $linkeditemnumber){ - my $linkeditem =$hostitem; - # append linked items if they exist - push @fields, $linkeditem if $linkeditem; + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + my $analyticsfield = '773'; + if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { + $analyticsfield = '773'; + } elsif ($marcflavor eq 'UNIMARC') { + $analyticsfield = '461'; + } + foreach my $hostfield ( $marcrecord->field($analyticsfield)) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + if( $hostbiblionumber ) { + my $hostbiblio = GetMarcBiblio({ + biblionumber => $hostbiblionumber, + embed_items => 1 }); + my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); + if( $hostbiblio ) { + my @hostitems = $hostbiblio->field($itemfield); + foreach my $hostitem (@hostitems){ + if ($hostitem->subfield("9") eq $linkeditemnumber){ + my $linkeditem =$hostitem; + # append linked items if they exist + push @fields, $linkeditem if $linkeditem; + } } } } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index a7c24ef3d9..51fa3af040 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -481,21 +481,22 @@ $template->param( OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"), ); -# adding items linked via host biblios - -my $analyticfield = '773'; -if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ - $analyticfield = '773'; -} elsif ($marcflavour eq 'UNIMARC') { - $analyticfield = '461'; -} -foreach my $hostfield ( $record->field($analyticfield)) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - my @hostitemInfos = GetItemsInfo($hostbiblionumber); - foreach my $hostitemInfo (@hostitemInfos){ - if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ - push(@all_items, $hostitemInfo); +if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding items linked via host biblios + my $analyticfield = '773'; + if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ + $analyticfield = '773'; + } elsif ($marcflavour eq 'UNIMARC') { + $analyticfield = '461'; + } + foreach my $hostfield ( $record->field($analyticfield)) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + my @hostitemInfos = GetItemsInfo($hostbiblionumber); + foreach my $hostitemInfo (@hostitemInfos){ + if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ + push(@all_items, $hostitemInfo); + } } } } -- 2.39.5