@@ -, +, @@ CanItemBeReserved - Check if borrower has reached the maximum number of holds allowed (syspref maxreserves) ---------- 1 hold for a borrower than 1 hold for a borrower identical than before the patch. --- C4/Reserves.pm | 23 +++++++++++++++++++++-- reserve/request.pl | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -274,7 +274,17 @@ See CanItemBeReserved() for possible return values. sub CanBookBeReserved{ my ($borrowernumber, $biblionumber, $pickup_branchcode) = @_; + 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' }; + } + my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); + #get items linked via host records my @hostitems = get_hostitemnumbers_of($biblionumber); if (@hostitems){ @@ -286,7 +296,8 @@ sub CanBookBeReserved{ $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode ); return { status => 'OK' } if $canReserve->{status} eq 'OK'; } - return $canReserve; + + return { status => 'none_available' }; } =head2 CanItemBeReserved @@ -303,6 +314,7 @@ sub CanBookBeReserved{ { status => libraryNotFound }, if given branchcode is not an existing library { 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 => alreadyReserved }, if the borrower has already reserved this item. =cut @@ -336,6 +348,13 @@ sub CanItemBeReserved { return { status =>'itemAlreadyOnHold' } if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); + # 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{ @@ -370,7 +389,7 @@ sub CanItemBeReserved { $ruleitemtype = '*'; } - my $holds = Koha::Holds->search( + $holds = Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $item->biblionumber, --- a/reserve/request.pl +++ a/reserve/request.pl @@ -240,7 +240,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; } --