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

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