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

(-)a/C4/Reserves.pm (+41 lines)
Lines 458-463 sub CanReserveBeCanceledFromOpac { Link Here
458
458
459
}
459
}
460
460
461
# TODO: Should be moved to Koha::Objects
462
=head2 GetReserveCount
463
464
  $number = &GetReserveCount($borrowernumber);
465
466
this function returns the number of reservation for a borrower given on input arg.
467
468
=cut
469
470
sub GetReserveCount {
471
    my ($borrowernumber) = @_;
472
473
    my $dbh = C4::Context->dbh;
474
475
    my $count = 0; #added by 15516
476
    my $query = "
477
        SELECT COUNT(*) AS counter
478
        FROM reserves
479
        WHERE borrowernumber = ?
480
        AND reserve_group_id is NULL"; #added by 15516
481
    my $sth = $dbh->prepare($query);
482
    $sth->execute($borrowernumber);
483
    my $row = $sth->fetchrow_hashref;
484
485
    # section added by 15516
486
    $count += $row->{counter};
487
488
    $query = "
489
        SELECT COUNT(DISTINCT reserve_group_id) AS counter
490
        FROM reserves
491
        WHERE borrowernumber = ?
492
        AND reserve_group_id is not NULL
493
    ";
494
    $sth = $dbh->prepare($query);
495
    $sth->execute($borrowernumber);
496
    $row = $sth->fetchrow_hashref;
497
    $count += $row->{counter};
498
    # end of section added by 15516
499
    return $count;
500
}
501
461
=head2 GetOtherReserves
502
=head2 GetOtherReserves
462
503
463
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
504
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
(-)a/opac/opac-reserve.pl (-3 / +5 lines)
Lines 201-207 foreach my $biblioNumber (@biblionumbers) { Link Here
201
if ( $query->param('place_reserve') ) {
201
if ( $query->param('place_reserve') ) {
202
    my $reserve_cnt = 0;
202
    my $reserve_cnt = 0;
203
    if ($maxreserves) {
203
    if ($maxreserves) {
204
        $reserve_cnt = $patron->holds->count;
204
        # TODO: Should be: $reserve_cnt = $patron->holds->count;
205
        $reserve_cnt = GetReserveCount( $borrowernumber );
205
    }
206
    }
206
207
207
    # List is composed of alternating biblio/item/branch
208
    # List is composed of alternating biblio/item/branch
Lines 364-375 if ( $patron->is_debarred ) { Link Here
364
}
365
}
365
366
366
my $holds = $patron->holds;
367
my $holds = $patron->holds;
367
my $reserves_count = $holds->count;
368
#TODO: Should be: my $reserves_count = $holds->count;
369
my $reserves_count = GetReserveCount($borrowernumber);
368
$template->param( RESERVES => $holds->unblessed );
370
$template->param( RESERVES => $holds->unblessed );
369
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
371
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
370
    $template->param( message => 1 );
372
    $template->param( message => 1 );
371
    $noreserves = 1;
373
    $noreserves = 1;
372
    $template->param( too_many_reserves => $holds->count );
374
    $template->param( too_many_reserves => $reserves_count );
373
}
375
}
374
376
375
unless ( $noreserves ) {
377
unless ( $noreserves ) {
(-)a/t/db_dependent/Reserves/ReserveCount.t (-1 / +116 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
use t::lib::TestBuilder;
22
23
use C4::Context;
24
use C4::Biblio;
25
use C4::Items;
26
use C4::Reserves;
27
28
use Koha::Database;
29
30
31
32
my $dbh = C4::Context->dbh;
33
$dbh->{AutoCommit} = 0;
34
$dbh->{RaiseError} = 1;
35
36
my $builder = t::lib::TestBuilder->new();
37
38
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
39
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
40
my $borrower = $builder->build({
41
    source => 'Borrower',
42
    value => {
43
        branchcode   => $branchcode,
44
        categorycode => $categorycode
45
    }
46
});
47
my $borrowernumber = $borrower->{borrowernumber};
48
49
my $biblio = $builder->build( { source => 'Biblio', } );
50
my $biblionumber = $biblio->{biblionumber};
51
52
# Use AddReserve instead of TestBuilder because i don't manage
53
# to make TestBuilder set reserve_group_id to null. Idea ?
54
my $reserve_id = AddReserve($branchcode, $borrowernumber,
55
$biblionumber, $biblionumber, 1, undef, undef, undef
56
$biblio->{title}, undef, undef, undef);
57
58
is(GetReserveCount($borrowernumber), 1, 'Test borrower has 1 reserve.');
59
60
my $reserves_group = $builder->build({
61
    source => 'ReserveGroup',
62
    value => {
63
        reserve_group_id => 1
64
    }
65
});
66
67
my $reserve2 = $builder->build({
68
    source => 'Reserve',
69
    value => {
70
        borrowernumber => $borrowernumber,
71
        reserve_group_id => 1
72
    }
73
});
74
my $reserve3 = $builder->build({
75
    source => 'Reserve',
76
    value => {
77
        borrowernumber => $borrowernumber,
78
        reserve_group_id => 1
79
    }
80
});
81
82
is(GetReserveCount($borrowernumber), 2, 'Test borrower has 2 reserve.');
83
84
my $reserves_group2 = $builder->build({
85
    source => 'ReserveGroup',
86
    value => {
87
        reserve_group_id => 2
88
    }
89
});
90
my $reserve_group_id2 = $reserves_group2->{reserve_group_id};
91
92
my $reserve4 = $builder->build({
93
    source => 'Reserve',
94
    value => {
95
        borrowernumber => $borrowernumber,
96
        reserve_group_id => 2
97
    }
98
});
99
my $reserve5 = $builder->build({
100
    source => 'Reserve',
101
    value => {
102
        borrowernumber => $borrowernumber,
103
        reserve_group_id => 2
104
    }
105
});
106
my $reserve6 = $builder->build({
107
    source => 'Reserve',
108
    value => {
109
        borrowernumber => $borrowernumber,
110
        reserve_group_id => 2
111
    }
112
});
113
114
is(GetReserveCount($borrowernumber), 3, 'Test borrower has 2 reserve.');
115
116
$dbh->rollback;

Return to bug 15516