@@ -, +, @@ from opac-search.pl to searchResults() --- C4/Search.pm | 24 +++++++++++++++----- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 2 +- opac/opac-detail.pl | 2 +- opac/opac-search.pl | 21 ++--------------- 4 files changed, 22 insertions(+), 27 deletions(-) --- a/C4/Search.pm +++ a/C4/Search.pm @@ -25,7 +25,7 @@ use Lingua::Stem; use C4::Search::PazPar2; use XML::Simple; use C4::Dates qw(format_date); -use C4::Members qw(GetHideLostItemsPreference); +use C4::Members qw(GetHideLostItemsPreference GetMember); use C4::XSLT; use C4::Branch; use C4::Reserves; # GetReserveStatus @@ -1833,7 +1833,7 @@ Format results in a form suitable for passing to the template # IMO this subroutine is pretty messy still -- it's responsible for # building the HTML output for the template sub searchResults { - my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_; + my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults, $borrowernumber ) = @_; my $dbh = C4::Context->dbh; my @newresults; @@ -1863,6 +1863,12 @@ sub searchResults { # get notforloan authorised value list (see $shelflocations FIXME) my $notforloan_authorised_value = GetAuthValCode('items.notforloan',''); + my $userenv = C4::Context->userenv; + my $hide_lost_items = GetHideLostItemsPreference($userenv->{'number'}); + + # $borrowernumber is passed for opac search + my $borrower = $borrowernumber ? GetMember( borrowernumber => $borrowernumber ) : undef; + #Build itemtype hash #find itemtype & itemtype image my %itemtypes; @@ -2038,13 +2044,15 @@ sub searchResults { my $onloan_count = 0; my $longoverdue_count = 0; my $other_count = 0; - my $withdrawn_count = 0; + my $withdrawn_count = 0; my $itemlost_count = 0; my $hideatopac_count = 0; my $itembinding_count = 0; my $itemdamaged_count = 0; my $item_in_transit_count = 0; my $can_place_holds = 0; + # If no borrower no point checking issuing_rules + my $can_place_item_holds = $borrower ? 0 : 1; my $item_onhold_count = 0; my $notforloan_count = 0; my $items_count = scalar(@fields); @@ -2091,8 +2099,7 @@ sub searchResults { my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item - my $userenv = C4::Context->userenv; - if ( $item->{onloan} && !(C4::Members::GetHideLostItemsPreference($userenv->{'number'}) && $item->{itemlost}) ) { + if ( $item->{onloan} && !($hide_lost_items && $item->{itemlost}) ) { $onloan_count++; my $key = $prefix . $item->{onloan} . $item->{barcode}; $onloan_items->{$key}->{due_date} = format_date($item->{onloan}); @@ -2203,6 +2210,11 @@ sub searchResults { $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} ); } } + # ||= because we only need one + $can_place_item_holds + ||= IsAvailableForItemLevelRequest($item, $borrower) && + OPACItemHoldsAllowed($item, $borrower) + if $can_place_holds && $borrower; } # notforloan, item level and biblioitem level # if all items are hidden, do not show the record @@ -2237,7 +2249,7 @@ sub searchResults { $can_place_holds = 0; } } - $oldbiblio->{norequests} = 1 unless $can_place_holds; + $oldbiblio->{norequests} = !($can_place_holds && $can_place_item_holds); $oldbiblio->{itemsplural} = 1 if $items_count > 1; $oldbiblio->{items_count} = $items_count; $oldbiblio->{available_items_loop} = \@available_items_loop; --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -471,7 +471,7 @@