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

(-)a/C4/Reserves.pm (-4 / +4 lines)
Lines 461-483 sub CanItemBeReserved { Link Here
461
    };
461
    };
462
    $search_params->{found} = undef if $params->{ignore_found_holds};
462
    $search_params->{found} = undef if $params->{ignore_found_holds};
463
463
464
    my $holds = Koha::Holds->search($search_params);
464
    my $holds_count = Koha::Holds->count_holds($search_params);
465
    if (   defined $holds_per_record && $holds_per_record ne '' ){
465
    if (   defined $holds_per_record && $holds_per_record ne '' ){
466
        if ( $holds_per_record == 0 ) {
466
        if ( $holds_per_record == 0 ) {
467
            return { status => "noReservesAllowed" };
467
            return { status => "noReservesAllowed" };
468
        }
468
        }
469
        if ( !$params->{ignore_hold_counts} && $holds->count() >= $holds_per_record ) {
469
        if ( !$params->{ignore_hold_counts} && $holds_count >= $holds_per_record ) {
470
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
470
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
471
        }
471
        }
472
    }
472
    }
473
473
474
    my $today_holds = Koha::Holds->search({
474
    my $today_holds_count = Koha::Holds->count_holds({
475
        borrowernumber => $borrowernumber,
475
        borrowernumber => $borrowernumber,
476
        reservedate    => dt_from_string->date
476
        reservedate    => dt_from_string->date
477
    });
477
    });
478
478
479
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne ''
479
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne ''
480
        && $today_holds->count() >= $holds_per_day )
480
        && $today_holds_count >= $holds_per_day )
481
    {
481
    {
482
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
482
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
483
    }
483
    }
(-)a/Koha/Holds.pm (-7 / +18 lines)
Lines 139-156 sub get_items_that_can_fill { Link Here
139
    )->filter_by_for_hold();
139
    )->filter_by_for_hold();
140
}
140
}
141
141
142
=head3 count_grouped
142
=head3 count_holds
143
143
144
    $holds->count_grouped();
144
    $holds->count_holds( $search_params );
145
145
146
Return number of hold, where hold group is counted as one hold
146
This overwrites the default count().
147
148
Return the number of holds, where a hold group is counted as one hold.
147
149
148
=cut
150
=cut
149
151
150
sub count_grouped {
152
sub count_holds {
151
    my ($self) = @_;
153
    my ( $self, $search_params ) = @_;
152
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
154
153
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
155
    $search_params = {
156
        hold_group_id => undef,
157
    };
158
    my $holds_without_group_count = $self->search( $search_params )->count();
159
160
    $search_params = {
161
        hold_group_id => { '!=', undef },
162
    };
163
    my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' })->count();
164
154
    return $holds_without_group_count + $hold_groups_count;
165
    return $holds_without_group_count + $hold_groups_count;
155
}
166
}
156
167
(-)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 202-208 if ($borrowernumber_hold && !$action) { Link Here
202
    # we check the reserves of the user, and if they can reserve a document
202
    # we check the reserves of the user, and if they can reserve a document
203
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
203
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
204
204
205
    my $reserves_count = $patron->holds->count;
205
    my $reserves_count = $patron->holds->count_holds;
206
206
207
    my $new_reserves_count = scalar( @biblionumbers );
207
    my $new_reserves_count = scalar( @biblionumbers );
208
208
(-)a/t/db_dependent/Koha/Holds.t (-5 / +4 lines)
Lines 500-506 subtest 'get_items_that_can_fill' => sub { Link Here
500
500
501
};
501
};
502
502
503
subtest 'count_grouped' => sub {
503
subtest 'count_holds' => sub {
504
    plan tests => 3;
504
    plan tests => 3;
505
    $schema->storage->txn_begin;
505
    $schema->storage->txn_begin;
506
506
Lines 517-523 subtest 'count_grouped' => sub { Link Here
517
            },
517
            },
518
        });
518
        });
519
519
520
    is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.');
520
    is($patron->holds->count_holds, 1, 'Test patron has 1 hold.');
521
521
522
    my $hold_group = $builder->build_object({
522
    my $hold_group = $builder->build_object({
523
        class => 'Koha::HoldGroups',
523
        class => 'Koha::HoldGroups',
Lines 538-544 subtest 'count_grouped' => sub { Link Here
538
        }
538
        }
539
    });
539
    });
540
540
541
    is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.');
541
    is($patron->holds->count_holds, 2, 'Test patron has 2 holds.');
542
542
543
    my $hold_group2 = $builder->build_object({
543
    my $hold_group2 = $builder->build_object({
544
        class => 'Koha::HoldGroups',
544
        class => 'Koha::HoldGroups',
Lines 566-572 subtest 'count_grouped' => sub { Link Here
566
        }
566
        }
567
    });
567
    });
568
568
569
    is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.');
569
    is($patron->holds->count_holds, 3, 'Test patron has 3 holds.');
570
570
571
    $schema->storage->txn_rollback;
571
    $schema->storage->txn_rollback;
572
};
572
};
573
- 

Return to bug 15516