@@ -, +, @@ --- C4/Reserves.pm | 8 ++++---- Koha/Holds.pm | 24 +++++++++++++++++------- opac/opac-reserve.pl | 2 +- reserve/request.pl | 2 +- t/db_dependent/Koha/Holds.t | 8 ++++---- 5 files changed, 27 insertions(+), 17 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -458,23 +458,23 @@ sub CanItemBeReserved { }; $search_params->{found} = undef if $params->{ignore_found_holds}; - my $holds = Koha::Holds->search($search_params); + my $holds_count = Koha::Holds->count_holds($search_params); if ( defined $holds_per_record && $holds_per_record ne '' ){ if ( $holds_per_record == 0 ) { return { status => "noReservesAllowed" }; } - if ( !$params->{ignore_hold_counts} && $holds->count() >= $holds_per_record ) { + if ( !$params->{ignore_hold_counts} && $holds_count >= $holds_per_record ) { return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record }; } } - my $today_holds = Koha::Holds->search({ + my $today_holds_count = Koha::Holds->count_holds({ borrowernumber => $borrowernumber, reservedate => dt_from_string->date }); if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '' - && $today_holds->count() >= $holds_per_day ) + && $today_holds_count >= $holds_per_day ) { return { status => 'tooManyReservesToday', limit => $holds_per_day }; } --- a/Koha/Holds.pm +++ a/Koha/Holds.pm @@ -153,18 +153,28 @@ sub get_items_that_can_fill { ); } -=head3 count_grouped +=head3 count - $holds->count_grouped(); + $holds->count( $search_params ); -Return number of hold, where hold group is counted as one hold +This overwrites the default count(). +Return the number of holds, where a hold group is counted as one hold. =cut -sub count_grouped { - my ($self) = @_; - my $holds_without_group_count = $self->search({ hold_group_id => undef })->count(); - my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count(); +sub count_holds { + my ( $self, $search_params ) = @_; + + $search_params = { + hold_group_id => undef, + }; + my $holds_without_group_count = $self->search( $search_params )->count(); + + $search_params = { + hold_group_id => { '!=', undef }, + }; + my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' })->count(); + return $holds_without_group_count + $hold_groups_count; } --- a/opac/opac-reserve.pl +++ a/opac/opac-reserve.pl @@ -196,7 +196,7 @@ foreach my $biblioNumber (@biblionumbers) { if ( $query->param('place_reserve') ) { my $reserve_cnt = 0; if ($maxreserves) { - $reserve_cnt = $patron->holds->count_grouped; + $reserve_cnt = $patron->holds->count_holds; } # List is composed of alternating biblio/item/branch --- a/reserve/request.pl +++ a/reserve/request.pl @@ -182,7 +182,7 @@ if ($borrowernumber_hold && !$action) { # we check the reserves of the user, and if they can reserve a document # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ... - my $reserves_count = $patron->holds->count; + my $reserves_count = $patron->holds->count_holds; my $new_reserves_count = scalar( @biblionumbers ); --- a/t/db_dependent/Koha/Holds.t +++ a/t/db_dependent/Koha/Holds.t @@ -500,7 +500,7 @@ subtest 'get_items_that_can_fill' => sub { }; -subtest 'count_grouped' => sub { +subtest 'count_holds' => sub { plan tests => 3; $schema->storage->txn_begin; @@ -517,7 +517,7 @@ subtest 'count_grouped' => sub { }, }); - is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.'); + is($patron->holds->count_holds, 1, 'Test patron has 1 hold.'); my $hold_group = $builder->build_object({ class => 'Koha::HoldGroups', @@ -538,7 +538,7 @@ subtest 'count_grouped' => sub { } }); - is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.'); + is($patron->holds->count_holds, 2, 'Test patron has 2 holds.'); my $hold_group2 = $builder->build_object({ class => 'Koha::HoldGroups', @@ -566,7 +566,7 @@ subtest 'count_grouped' => sub { } }); - is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.'); + is($patron->holds->count_holds, 3, 'Test patron has 3 holds.'); $schema->storage->txn_rollback; }; --