Bug 23414: Easy readability and simplify logic in buildKohaItemsNamespace

This patch improves true/false logic and avoid autovivication.
Also note that xml_escape already deals with empty string.

An unecessary call to GetReserveStatus is removed.

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-11-04 16:29:23 +01:00 committed by Martin Renvoize
parent ff7c422af0
commit 89cd2c4400
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -292,10 +292,14 @@ Is only used in this module currently.
sub buildKohaItemsNamespace {
my ($biblionumber, $hidden_items) = @_;
my $search_params;
$search_params->{'me.biblionumber'} = $biblionumber;
$search_params->{'me.itemnumber'} = { not_in => $hidden_items } if $hidden_items;
my @items = Koha::Items->search($search_params,{prefetch=>['branchtransfers','reserves']});
$hidden_items ||= [];
my @items = Koha::Items->search(
{
'me.biblionumber' => $biblionumber,
'me.itemnumber' => { not_in => $hidden_items }
},
{ prefetch => [ 'branchtransfers', 'reserves' ] }
);
my $shelflocations =
{ map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => "", kohafield => 'items.location' } ) };
@ -305,14 +309,10 @@ sub buildKohaItemsNamespace {
my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
my $location = "";
my $ccode = "";
my $xml = '';
for my $item (@items) {
my $status;
my $reservestatus = C4::Reserves::GetReserveStatus( $item->itemnumber );
if ($item->has_pending_hold) {
$status = 'Pending hold';
}
@ -343,12 +343,12 @@ sub buildKohaItemsNamespace {
else {
$status = "available";
}
my $homebranch = $item->homebranch? xml_escape($branches{$item->homebranch}):'';
my $holdingbranch = $item->holdingbranch? xml_escape($branches{$item->holdingbranch}):'';
$location = $item->location? xml_escape($shelflocations->{$item->location}||$item->location):'';
$ccode = $item->ccode? xml_escape($ccodes->{$item->ccode}||$item->ccode):'';
my $homebranch = xml_escape($branches{$item->homebranch});
my $holdingbranch = xml_escape($branches{$item->holdingbranch});
my $location = xml_escape($item->location && exists $shelflocations->{$item->location} ? $shelflocations->{$item->location} : $item->location);
my $ccode = xml_escape($item->ccode && exists $ccodes->{$item->ccode} ? $ccodes->{$item->ccode} : $item->ccode);
my $itemcallnumber = xml_escape($item->itemcallnumber);
my $stocknumber = $item->stocknumber? xml_escape($item->stocknumber):'';
my $stocknumber = xml_escape($item->stocknumber);
$xml .=
"<item>"
. "<homebranch>$homebranch</homebranch>"