Browse Source

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 <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Marcel de Rooy 3 years ago
committed by Nick Clemens
parent
commit
8480491cce
  1. 62
      C4/Items.pm

62
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

Loading…
Cancel
Save