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

(-)a/C4/Reserves.pm (-4 / +4 lines)
Lines 458-480 sub CanItemBeReserved { Link Here
458
    };
458
    };
459
    $search_params->{found} = undef if $params->{ignore_found_holds};
459
    $search_params->{found} = undef if $params->{ignore_found_holds};
460
460
461
    my $holds = Koha::Holds->search($search_params);
461
    my $holds_count = Koha::Holds->count_holds($search_params);
462
    if (   defined $holds_per_record && $holds_per_record ne '' ){
462
    if (   defined $holds_per_record && $holds_per_record ne '' ){
463
        if ( $holds_per_record == 0 ) {
463
        if ( $holds_per_record == 0 ) {
464
            return { status => "noReservesAllowed" };
464
            return { status => "noReservesAllowed" };
465
        }
465
        }
466
        if ( !$params->{ignore_hold_counts} && $holds->count() >= $holds_per_record ) {
466
        if ( !$params->{ignore_hold_counts} && $holds_count >= $holds_per_record ) {
467
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
467
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
468
        }
468
        }
469
    }
469
    }
470
470
471
    my $today_holds = Koha::Holds->search({
471
    my $today_holds_count = Koha::Holds->count_holds({
472
        borrowernumber => $borrowernumber,
472
        borrowernumber => $borrowernumber,
473
        reservedate    => dt_from_string->date
473
        reservedate    => dt_from_string->date
474
    });
474
    });
475
475
476
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne ''
476
    if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne ''
477
        && $today_holds->count() >= $holds_per_day )
477
        && $today_holds_count >= $holds_per_day )
478
    {
478
    {
479
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
479
        return { status => 'tooManyReservesToday', limit => $holds_per_day };
480
    }
480
    }
(-)a/Koha/Holds.pm (-7 / +17 lines)
Lines 153-170 sub get_items_that_can_fill { Link Here
153
    );
153
    );
154
}
154
}
155
155
156
=head3 count_grouped
156
=head3 count
157
157
158
    $holds->count_grouped();
158
    $holds->count( $search_params );
159
159
160
Return number of hold, where hold group is counted as one hold
160
This overwrites the default count().
161
Return the number of holds, where a hold group is counted as one hold.
161
162
162
=cut
163
=cut
163
164
164
sub count_grouped {
165
sub count_holds {
165
    my ($self) = @_;
166
    my ( $self, $search_params ) = @_;
166
    my $holds_without_group_count = $self->search({ hold_group_id => undef })->count();
167
167
    my $hold_groups_count = $self->search({ hold_group_id => { '!=' => undef }}, { group_by => 'me.hold_group_id' })->count();
168
    $search_params = {
169
        hold_group_id => undef,
170
    };
171
    my $holds_without_group_count = $self->search( $search_params )->count();
172
173
    $search_params = {
174
        hold_group_id => { '!=', undef },
175
    };
176
    my $hold_groups_count = $self->search( $search_params, { group_by => 'me.hold_group_id' })->count();
177
168
    return $holds_without_group_count + $hold_groups_count;
178
    return $holds_without_group_count + $hold_groups_count;
169
}
179
}
170
180
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 196-202 foreach my $biblioNumber (@biblionumbers) { Link Here
196
if ( $query->param('place_reserve') ) {
196
if ( $query->param('place_reserve') ) {
197
    my $reserve_cnt = 0;
197
    my $reserve_cnt = 0;
198
    if ($maxreserves) {
198
    if ($maxreserves) {
199
        $reserve_cnt = $patron->holds->count_grouped;
199
        $reserve_cnt = $patron->holds->count_holds;
200
    }
200
    }
201
201
202
    # List is composed of alternating biblio/item/branch
202
    # 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 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