@@ -, +, @@ --- C4/Reserves.pm | 17 +++++++++++++---- C4/Search.pm | 13 ++++++++++--- .../en/includes/opac-detail-sidebar.inc | 2 +- opac/opac-detail.pl | 3 ++- 4 files changed, 26 insertions(+), 9 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -330,6 +330,7 @@ sub CanBookBeReserved{ return { status =>'alreadypossession' }; } + my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); my $items; #get items linked via host records my @hostitemnumbers = get_hostitemnumbers_of($biblionumber); @@ -346,10 +347,16 @@ sub CanBookBeReserved{ my $canReserve = { status => '' }; my $patron = Koha::Patrons->find( $borrowernumber ); - while ( my $item = $items->next ) { - $canReserve = CanItemBeReserved( $patron, $item, $pickup_branchcode, $params ); - return { status => 'OK' } if $canReserve->{status} eq 'OK'; + foreach my $itemnumber (@itemnumbers) { + my $itemo = Koha::Items->find($itemnumber); + unless ( $canReserve->{status} eq 'OK' ) { + my $canItemBeReserved = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode, $params ); + $canReserve = $canItemBeReserved + # status can become 'OK' only if CanItemBeReserved && IsAvailableForItemLevelRequest + if $canItemBeReserved->{status} ne 'OK' and IsAvailableForItemLevelRequest($itemo, $patron, $pickup_branchcode); + } } + return $canReserve; } @@ -381,11 +388,13 @@ sub CanBookBeReserved{ =cut sub CanItemBeReserved { - my ( $patron, $item, $pickup_branchcode, $params ) = @_; + my ( $borrowernumber, $itemnumber, $pickup_branchcode, $params ) = @_; my $dbh = C4::Context->dbh; my $ruleitemtype; # itemtype of the matching issuing rule my $allowedreserves = 0; # Total number of holds allowed across all records, default to none + my $patron = Koha::Patrons->find($borrowernumber); + my $item = Koha::Items->find($itemnumber); # We check item branch if IndependentBranches is ON # and canreservefromotherbranches is OFF --- a/C4/Search.pm +++ a/C4/Search.pm @@ -1621,7 +1621,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, $xslt_variables ) = @_; + my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults, $xslt_variables, $borrowernumber ) = @_; my $dbh = C4::Context->dbh; my @newresults; @@ -1778,12 +1778,13 @@ 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 = 1; my $item_onhold_count = 0; my $notforloan_count = 0; my $item_recalled_count = 0; @@ -1855,6 +1856,7 @@ sub searchResults { if ( $item->{itemlost} ) { $onloan_items->{$key}->{longoverdue}++; $longoverdue_count++; + $can_place_holds = 0; } } @@ -2003,7 +2005,7 @@ sub searchResults { my $biblio_object = Koha::Biblios->find( $oldbiblio->{biblionumber} ); $oldbiblio->{biblio_object} = $biblio_object; - my $can_place_holds = 1; + $can_place_holds = 1; # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either if (!C4::Context->preference("item-level_itypes")) { if ($itemtype && $itemtype->{notforloan}) { @@ -2012,6 +2014,11 @@ sub searchResults { } else { $can_place_holds = $biblio_object->items->filter_by_for_hold()->count if $biblio_object; } + + if ( $borrowernumber and $can_place_holds ) { + $can_place_holds = (C4::Reserves::CanBookBeReserved( $borrowernumber, $oldbiblio->{biblionumber} )->{status} eq 'OK'); + } + $oldbiblio->{norequests} = 1 unless $can_place_holds; $oldbiblio->{items_count} = $items_count; $oldbiblio->{available_items_loop} = \@available_items_loop; --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -4,7 +4,7 @@ [% UNLESS ( norequests ) %] [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] [% IF Koha.Preference( 'OPACHoldRequests' ) == 1 %] - [% IF ( ReservableItems ) %] + [% IF ( CanBeReserved ) %]
  • Place hold
  • [% END %] [% END %] --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -258,7 +258,7 @@ if ($session->param('busc')) { for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; $hits = $results_hashref->{$server}->{"hits"}; - @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"}); + @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"}, undef, $patron); } return \@newresults; }#searchAgain @@ -775,6 +775,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { } } } +$template->param( 'CanBeReserved' => ($borrowernumber ? C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber )->{status} eq 'OK' : 1) ); if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) { $template->param( ReservableItems => 1 ); --