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

(-)a/C4/Reserves.pm (+41 lines)
Lines 520-525 sub CanReserveBeCanceledFromOpac { Link Here
520
520
521
}
521
}
522
522
523
# TODO: Should be moved to Koha::Objects
524
=head2 GetReserveCount
525
526
  $number = &GetReserveCount($borrowernumber);
527
528
this function returns the number of reservation for a borrower given on input arg.
529
530
=cut
531
532
sub GetReserveCount {
533
    my ($borrowernumber) = @_;
534
535
    my $dbh = C4::Context->dbh;
536
537
    my $count = 0; #added by 15516
538
    my $query = "
539
        SELECT COUNT(*) AS counter
540
        FROM reserves
541
        WHERE borrowernumber = ?
542
        AND reserve_group_id is NULL"; #added by 15516
543
    my $sth = $dbh->prepare($query);
544
    $sth->execute($borrowernumber);
545
    my $row = $sth->fetchrow_hashref;
546
547
    # section added by 15516
548
    $count += $row->{counter};
549
550
    $query = "
551
        SELECT COUNT(DISTINCT reserve_group_id) AS counter
552
        FROM reserves
553
        WHERE borrowernumber = ?
554
        AND reserve_group_id is not NULL
555
    ";
556
    $sth = $dbh->prepare($query);
557
    $sth->execute($borrowernumber);
558
    $row = $sth->fetchrow_hashref;
559
    $count += $row->{counter};
560
    # end of section added by 15516
561
    return $count;
562
}
563
523
=head2 GetOtherReserves
564
=head2 GetOtherReserves
524
565
525
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
566
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
(-)a/opac/opac-reserve.pl (-3 / +5 lines)
Lines 198-204 foreach my $biblioNumber (@biblionumbers) { Link Here
198
if ( $query->param('place_reserve') ) {
198
if ( $query->param('place_reserve') ) {
199
    my $reserve_cnt = 0;
199
    my $reserve_cnt = 0;
200
    if ($maxreserves) {
200
    if ($maxreserves) {
201
        $reserve_cnt = $patron->holds->count;
201
        # TODO: Should be: $reserve_cnt = $patron->holds->count;
202
        $reserve_cnt = GetReserveCount( $borrowernumber );
202
    }
203
    }
203
204
204
    # List is composed of alternating biblio/item/branch
205
    # List is composed of alternating biblio/item/branch
Lines 353-364 if ( $patron->is_debarred ) { Link Here
353
}
354
}
354
355
355
my $holds = $patron->holds;
356
my $holds = $patron->holds;
356
my $reserves_count = $holds->count;
357
#TODO: Should be: my $reserves_count = $holds->count;
358
my $reserves_count = GetReserveCount($borrowernumber);
357
$template->param( RESERVES => $holds->unblessed );
359
$template->param( RESERVES => $holds->unblessed );
358
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
360
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
359
    $template->param( message => 1 );
361
    $template->param( message => 1 );
360
    $noreserves = 1;
362
    $noreserves = 1;
361
    $template->param( too_many_reserves => $holds->count );
363
    $template->param( too_many_reserves => $reserves_count );
362
}
364
}
363
365
364
unless ( $noreserves ) {
366
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