From 5c3adab88fb409df680d46caccf1b1439ebf4bbf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Aug 2022 15:09:58 +0200 Subject: [PATCH] Bug 28702: Improve readability But removing the repetition Also prevent useless GetReserveStatus and GetTransfers (in a non-elegant way...) --- C4/Search.pm | 13 +++++++------ C4/XSLT.pm | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 9f9af157d4e..9fb84c73742 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1832,8 +1832,8 @@ sub searchResults { elsif ($item->{$otherbranch}) { # Last resort $item->{'branchname'} = $branches{$item->{$otherbranch}}; } - $item->{homebranch} = $branches{ $item->{homebranch} } if defined $item->{homebranch}; - $item->{holdingbranch} = $branches{ $item->{holdingbranch} } if defined $item->{holdingbranch}; + $item->{homebranch} &&= $branches{ $item->{homebranch} }; + $item->{holdingbranch} &&= $branches{ $item->{holdingbranch} }; my $prefix = ( $item->{$hbranch} ? $item->{$hbranch} . '--' : q{} ) @@ -1842,11 +1842,12 @@ sub searchResults { . ( $item->{itemcallnumber} ? $item->{itemcallnumber} : q{} ); # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item my $itemtype = C4::Context->preference("item-level_itypes")? $item->{itype}: $oldbiblio->{itemtype}; - $item->{itemtype} = $itemtype; - $item->{location} = $item->{location} && exists $shelflocations->{$item->{location}} ? $shelflocations->{$item->{location}} : $item->{location} ; - $item->{notforloan_description} = exists $notforloan_descriptions->{ $item->{notforloan} } ? $notforloan_descriptions->{ $item->{notforloan} } : "Not for loan"; - $item->{ccode_description} = defined $item->{ccode} && exists $ccodes->{ $item->{ccode} } ? $ccodes->{ $item->{ccode} } : $item->{ccode}; + $item->{itemtype} = $itemtype; + $item->{location} = $shelflocations->{$item->{location}} || $item->{location} ; + $item->{notforloan_description} = $notforloan_descriptions->{ $item->{notforloan} } || "Not for loan"; + $item->{ccode_description} = $ccodes->{ $item->{ccode} } || $item->{ccode}; $item->{notforloan_itemtype} = defined $itemtype && exists $itemtypes{ $itemtype } ? $itemtypes{ $itemtype }->{notforloan} : undef; + if ( $item->{onloan} and $logged_in_user and !( $patron_category_hide_lost_items and $item->{itemlost} ) ) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 053b674fa35..da054a7cf47 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -334,8 +334,9 @@ sub buildKohaItemsNamespace { $recalls_count = Koha::Recalls->search({ item_id => $item->{itemnumber}, status => 'waiting' })->count; } - my $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} ); - my $transfer = C4::Circulation::GetTransfers($item->{itemnumber}); + # Don't call GetReserveStatus if we don't need it + my $reservestatus = !$recalls_count ? C4::Reserves::GetReserveStatus( $item->{itemnumber} ) : undef; + if ($recalls_count) { # recalls take priority over holds @@ -350,7 +351,7 @@ sub buildKohaItemsNamespace { $status = 'other'; $substatus = 'Waiting'; } - elsif ($transfer) { + elsif (C4::Circulation::GetTransfers($item->{itemnumber})){ $status = 'other'; $substatus = 'In transit'; } -- 2.25.1