From 419d816f1fa1c5661622c83c0cf3b5f7fe09d25b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Jan 2021 09:03:31 +0100 Subject: [PATCH] Bug 24488: create a loop to avoid copy paste Signed-off-by: Marcel de Rooy JD amended patch: Rename variables Signed-off-by: Jonathan Druart --- circ/pendingreserves.pl | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index bc7b25b001..e827b89086 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -272,23 +272,22 @@ foreach my $bibnum ( @biblionumbers ){ } $hold_info->{itemtypes} = \@res_itemtypes; - # get available locations for each biblio - $hold_info->{locations} = [ uniq map { defined $_->location ? $_->location : () } @$items ]; - - # get available callnumbers for each biblio - $hold_info->{callnumbers} = [ uniq map { defined $_->itemcallnumber ? $_->itemcallnumber : () } @$items ]; - - # get available enumchrons for each biblio - $hold_info->{enumchrons} = [ uniq map { defined $_->enumchron ? $_->enumchron : () } @$items ]; - - # get available copynumbers for each biblio - $hold_info->{copynumbers} = [ uniq map { defined $_->copynumber ? $_->copynumber : () } @$items ]; - - # get available barcodes for each biblio - $hold_info->{barcodes} = [ uniq map { defined $_->barcode ? $_->barcode : () } @$items ]; - - # get available holding branches for each biblio - $hold_info->{holdingbranches} = [ uniq map { defined $_->holdingbranch ? $_->holdingbranch : () } @$items ]; + # get available values for each biblio + my $fields = { + locations => 'location', + callnumbers => 'itemcallnumber', + enumchrons => 'enumchron', + copynumbers => 'copynumber', + barcodes => 'barcode', + holdingbranches => 'holdingbranch' + }; + + while ( + my ( $key, $field ) = each %$fields ) + { + $hold_info->{$key} = + [ uniq map { defined $_->$field ? $_->$field : () } @$items ]; + } # items available $hold_info->{items_count} = $items_count; -- 2.39.5