View | Details | Raw Unified | Return to bug 15516
Collapse All | Expand All

(-)a/C4/Reserves.pm (-4 / +4 lines)
Lines 522-539 sub CanItemBeReserved { Link Here
522
                biblionumber   => $item->biblionumber,
522
                biblionumber   => $item->biblionumber,
523
            };
523
            };
524
            $search_params->{found} = undef if $params->{ignore_found_holds};
524
            $search_params->{found} = undef if $params->{ignore_found_holds};
525
            my $holds = Koha::Holds->search($search_params);
525
            my $holds_count = Koha::Holds->count_holds($search_params);
526
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds->count() >= $holds_per_record;
526
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds_count >= $holds_per_record;
527
        }
527
        }
528
    }
528
    }
529
529
530
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '')
530
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '')
531
    {
531
    {
532
        my $today_holds = Koha::Holds->search({
532
        my $today_holds_count = Koha::Holds->count_holds({
533
            borrowernumber => $patron->borrowernumber,
533
            borrowernumber => $patron->borrowernumber,
534
            reservedate    => dt_from_string->date
534
            reservedate    => dt_from_string->date
535
        });
535
        });
536
        return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds->count() >= $holds_per_day;
536
        return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds_count >= $holds_per_day;
537
    }
537
    }
538
538
539
    # we check if it's ok or not
539
    # we check if it's ok or not
(-)a/Koha/Holds.pm (-7 / +18 lines)
Lines 178-195 sub filter_out_has_cancellation_requests { Link Here
178
        { join => 'cancellation_requests' } );
178
        { join => 'cancellation_requests' } );
179
}
179
}
180
180
181
=head3 count_grouped
181
=head3 count_holds
182
182
183
    $holds->count_grouped();
183
    $holds->count_holds( $search_params );
184
184
185
Return number of hold, where hold group is counted as one hold
185
This overwrites the default count().
186
187
Return the number of holds, where a hold group is counted as one hold.
186
188
187
=cut
189
=cut
188
190
189
sub count_grouped {
191
sub count_holds {
190
    my ($self) = @_;
192
    my ( $self, $search_params ) = @_;
191
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
193
192
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
194
    $search_params = {
195
        hold_group_id => undef,
196
    };
197
    my $holds_without_group_count = $self->search( $search_params )->count();
198
199
    $search_params = {
200
        hold_group_id => { '!=', undef },
201
    };
202
    my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' })->count();
203
193
    return $holds_without_group_count + $hold_groups_count;
204
    return $holds_without_group_count + $hold_groups_count;
194
}
205
}
195
206
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 193-199 foreach my $biblioNumber (@biblionumbers) { Link Here
193
if ( $query->param('place_reserve') ) {
193
if ( $query->param('place_reserve') ) {
194
    my $reserve_cnt = 0;
194
    my $reserve_cnt = 0;
195
    if ($maxreserves) {
195
    if ($maxreserves) {
196
        $reserve_cnt = $patron->holds->count_grouped;
196
        $reserve_cnt = $patron->holds->count_holds;
197
    }
197
    }
198
198
199
    # List is composed of alternating biblio/item/branch
199
    # List is composed of alternating biblio/item/branch
(-)a/reserve/request.pl (-1 / +1 lines)
Lines 182-188 if ($borrowernumber_hold && !$action) { Link Here
182
    # we check the reserves of the user, and if they can reserve a document
182
    # we check the reserves of the user, and if they can reserve a document
183
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
183
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
184
184
185
    my $reserves_count = $patron->holds->count;
185
    my $reserves_count = $patron->holds->count_holds;
186
186
187
    my $new_reserves_count = scalar( @biblionumbers );
187
    my $new_reserves_count = scalar( @biblionumbers );
188
188
(-)a/t/db_dependent/Koha/Holds.t (-5 / +4 lines)
Lines 641-647 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
641
    };
641
    };
642
};
642
};
643
643
644
subtest 'count_grouped' => sub {
644
subtest 'count_holds' => sub {
645
    plan tests => 3;
645
    plan tests => 3;
646
    $schema->storage->txn_begin;
646
    $schema->storage->txn_begin;
647
647
Lines 658-664 subtest 'count_grouped' => sub { Link Here
658
            },
658
            },
659
        });
659
        });
660
660
661
    is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.');
661
    is($patron->holds->count_holds, 1, 'Test patron has 1 hold.');
662
662
663
    my $hold_group = $builder->build_object({
663
    my $hold_group = $builder->build_object({
664
        class => 'Koha::HoldGroups',
664
        class => 'Koha::HoldGroups',
Lines 679-685 subtest 'count_grouped' => sub { Link Here
679
        }
679
        }
680
    });
680
    });
681
681
682
    is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.');
682
    is($patron->holds->count_holds, 2, 'Test patron has 2 holds.');
683
683
684
    my $hold_group2 = $builder->build_object({
684
    my $hold_group2 = $builder->build_object({
685
        class => 'Koha::HoldGroups',
685
        class => 'Koha::HoldGroups',
Lines 707-713 subtest 'count_grouped' => sub { Link Here
707
        }
707
        }
708
    });
708
    });
709
709
710
    is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.');
710
    is($patron->holds->count_holds, 3, 'Test patron has 3 holds.');
711
711
712
    $schema->storage->txn_rollback;
712
    $schema->storage->txn_rollback;
713
};
713
};
714
- 

Return to bug 15516