From e605a7353f595b25f0cb64b322060db3637bfd08 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 26 Mar 2014 10:51:59 +0100 Subject: [PATCH] Bug 11999: Add maxreserves check in CanBookBeReserved and CanItemBeReserved - Check if borrower has reached the maximum number of holds allowed (syspref maxreserves) The goal of this patch is to do these checks also when using ILS-DI services HoldTitle and HoldItem Test plan: ---------- Before patch: 1/ Set syspref maxreserves to 1 2/ Place some holds through ILS-DI and note that you can place more than 1 hold for a borrower Apply the patch 3/ Place some holds through ILS-DI, you shouldn't be able to place more than 1 hold for a borrower 4/ Try to place holds on staff interface and OPAC. The behaviour must be identical than before the patch. Maxreserves and alreadyreserved works on ILSDI Maxreserves works also on staff and opac Already reserves works also on staff and opac tests on t/db_dependent/Reserves.t and t/db_dependent/Holds.t passe (using koha_ut db) Signed-off-by: Alex Sassmannshausen Signed-off-by: Alex Arnaud --- C4/Reserves.pm | 20 +++++++++++++++++++- reserve/request.pl | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 8941d4f72c..68ceb37c6b 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -327,7 +327,17 @@ sub CanBookBeReserved{ return { status =>'alreadypossession' }; } + my $patron = Koha::Patrons->find($borrowernumber); + my $holds = $patron->holds; + + # Check if borrower has reached the maximum number of holds allowed + my $maxreserves = C4::Context->preference('maxreserves'); + if ($maxreserves && $holds->count >= $maxreserves) { + return { status => 'tooManyReserves', limit => $maxreserves }; + } + my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); + #get items linked via host records my @hostitems = get_hostitemnumbers_of($biblionumber); if (@hostitems){ @@ -365,6 +375,7 @@ sub CanBookBeReserved{ { status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode { status => pickupNotInHoldGroup }, pickup location is not in hold group, and pickup locations are only allowed from hold groups. + { status => alreadyReserved }, if the borrower has already reserved this item. =cut @@ -402,6 +413,13 @@ sub CanItemBeReserved { return { status =>'alreadypossession' }; } + # Check if borrower has reached the maximum number of holds allowed + my $maxreserves = C4::Context->preference('maxreserves'); + my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } ); + if ($maxreserves && $holds->count >= $maxreserves) { + return { status => 'tooManyReserves', limit => $maxreserves }; + } + my $controlbranch = C4::Context->preference('ReservesControlBranch'); my $querycount = q{ @@ -456,7 +474,7 @@ sub CanItemBeReserved { }; $search_params->{found} = undef if $params->{ignore_found_holds}; - my $holds = Koha::Holds->search($search_params); + $holds = Koha::Holds->search($search_params); if ( defined $holds_per_record && $holds_per_record ne '' ){ if ( $holds_per_record == 0 ) { return { status => "noReservesAllowed" }; diff --git a/reserve/request.pl b/reserve/request.pl index 49d8a2fa26..ca8e678275 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -316,7 +316,9 @@ foreach my $biblionumber (@biblionumbers) { $exceeded_holds_per_record = 1; $biblioloopiter{ $canReserve->{status} } = 1; } - elsif ( $canReserve->{status} eq 'ageRestricted' ) { + elsif ( grep { $canReserve->{status} eq $_ } + (qw(ageRestricted alreadyReserved none_available)) ) + { $template->param( $canReserve->{status} => 1 ); $biblioloopiter{ $canReserve->{status} } = 1; } -- 2.30.2