From 925a68e901ed63f3d550cc1a6aafa3a90ffd5ac1 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Fri, 18 May 2018 13:36:47 -0400 Subject: [PATCH] Bug 30556: Place hold button doesn't show when not allowed When On shelf holds holds allowed is on "If all unavailable", the Place hold button is not showed. To test: 1. Create a circulation rule with on shelf holds set to "If all unavailable" 2. Create or modify a record to match the items itype to the circulation rule 3. Use a patron matching the circ rule category to log into the opac 4. Look for the record 5. Notice that the Place hold button is there, even thought it's not allowed 6. Apply the patch. 7. The button is not there. --- 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(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index d291a888e6..6601fa2083 100644 --- a/C4/Reserves.pm +++ b/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 diff --git a/C4/Search.pm b/C4/Search.pm index 85a02bf5a2..3fd137a954 100644 --- a/C4/Search.pm +++ b/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; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index a3cbb23590..1a835a0692 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/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 %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 00c52eb5aa..3ff0629a9b 100755 --- a/opac/opac-detail.pl +++ b/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 ); -- 2.25.1