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

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