+ [% holds = hold_group.holds %]
[% IF holds.size %]
@@ -17,7 +17,7 @@
[% FOREACH hold IN holds %]
- [% biblio = Biblio.Get(hold.biblionumber) %]
+ [% biblio = hold.biblio %]
[% biblio.title | html %] |
[% hold.priority | html %] |
--- a/opac/opac-reserve.pl
+++ a/opac/opac-reserve.pl
@@ -195,8 +195,7 @@ foreach my $biblioNumber (@biblionumbers) {
if ( $query->param('place_reserve') ) {
my $reserve_cnt = 0;
if ($maxreserves) {
- # TODO: Should be: $reserve_cnt = $patron->holds->count;
- $reserve_cnt = GetHoldCount( $borrowernumber );
+ $reserve_cnt = $patron->holds->count_grouped;
}
# List is composed of alternating biblio/item/branch
--- a/reserve/hold-group.pl
+++ a/reserve/hold-group.pl
@@ -20,23 +20,21 @@ use CGI qw( -utf8 );
use C4::Auth;
use C4::Output;
-use C4::Reserves;
+use Koha::HoldGroups;
my $cgi = new CGI;
my ($template, $loggedinuser, $cookie) = get_template_and_user({
template_name => "reserve/hold-group.tt",
query => $cgi,
type => "intranet",
- authnotrequired => 0,
flagsrequired => { circulate => 'circulate_remaining_permissions' },
});
my $hold_group_id = $cgi->param('hold_group_id');
-my @holds = GetHoldGroupHolds($hold_group_id);
+my $hold_group = Koha::HoldGroups->find($hold_group_id);
$template->param(
- hold_group_id => $hold_group_id,
- holds => \@holds,
+ hold_group => $hold_group,
);
output_html_with_http_headers $cgi, $cookie, $template->output;
--- a/reserve/placerequest.pl
+++ a/reserve/placerequest.pl
@@ -32,6 +32,7 @@ use C4::Circulation;
use C4::Members;
use C4::Auth qw/checkauth/;
+use Koha::HoldGroups;
use Koha::Items;
use Koha::Patrons;
@@ -77,9 +78,9 @@ my $found;
if ( $type eq 'str8' && $borrower ) {
- my $hold_group_id;
+ my $hold_group;
if ((@biblionumbers > 1) && $requestany) {
- $hold_group_id = AddHoldGroup();
+ $hold_group = Koha::HoldGroup->new->store;
}
foreach my $biblionumber ( keys %bibinfos ) {
@@ -144,7 +145,7 @@ if ( $type eq 'str8' && $borrower ) {
found => $found,
itemtype => $itemtype,
non_priority => $non_priority,
- hold_group_id => $hold_group_id,
+ hold_group_id => $hold_group ? $hold_group->id : undef,
}
);
}
--- a/t/db_dependent/Koha/HoldGroup.t
+++ a/t/db_dependent/Koha/HoldGroup.t
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+
+# Copyright 2020 Koha Development team
+#
+# This file is part of Koha
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see .
+
+use Modern::Perl;
+
+use Test::More tests => 1;
+
+use t::lib::TestBuilder;
+
+my $schema = Koha::Database->new->schema;
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'holds tests' => sub {
+
+ plan tests => 2;
+
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object({ class => 'Koha::Patrons' });
+ my $hold_group = $builder->build_object({ class => 'Koha::HoldGroups' });
+ my $hold = $builder->build_object(
+ {
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron->borrowernumber,
+ hold_group_id => $hold_group->hold_group_id,
+ }
+ }
+ );
+
+ my $holds = $hold_group->holds;
+ is( ref($holds), 'Koha::Holds', 'Right type' );
+ my $hold_from_group = $holds->next;
+ is( $hold_from_group->id, $hold->id, 'Right object' );
+
+ $schema->storage->txn_rollback;
+};
--- a/t/db_dependent/Koha/Holds.t
+++ a/t/db_dependent/Koha/Holds.t
@@ -19,7 +19,7 @@
use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Test::Warn;
use C4::Reserves;
@@ -410,4 +410,75 @@ subtest 'Desks' => sub {
$schema->storage->txn_rollback;
+subtest 'count_grouped' => sub {
+ plan tests => 3;
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object({
+ class => 'Koha::Patrons',
+ });
+ my $patron_id = $patron->borrowernumber;
+
+ my $hold1 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => undef,
+ },
+ });
+
+ is($patron->holds->count_grouped, 1, 'Test patron has 1 hold.');
+
+ my $hold_group = $builder->build_object({
+ class => 'Koha::HoldGroups',
+ });
+
+ my $hold2 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => $hold_group->hold_group_id,
+ }
+ });
+ my $hold3 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => $hold_group->hold_group_id,
+ }
+ });
+
+ is($patron->holds->count_grouped, 2, 'Test patron has 2 holds.');
+
+ my $hold_group2 = $builder->build_object({
+ class => 'Koha::HoldGroups',
+ });
+
+ my $hold4 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => $hold_group2->hold_group_id,
+ }
+ });
+ my $hold5 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => $hold_group2->hold_group_id,
+ }
+ });
+ my $hold6 = $builder->build_object({
+ class => 'Koha::Holds',
+ value => {
+ borrowernumber => $patron_id,
+ hold_group_id => $hold_group2->hold_group_id,
+ }
+ });
+
+ is($patron->holds->count_grouped, 3, 'Test patron has 3 holds.');
+
+ $schema->storage->txn_rollback;
+};
+
1;
--- a/t/db_dependent/Reserves/HoldCount.t
+++ a/t/db_dependent/Reserves/HoldCount.t
@@ -1,116 +0,0 @@
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Koha is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# Koha is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Koha; if not, see .
-
-use Modern::Perl;
-
-use Test::More tests => 3;
-use t::lib::TestBuilder;
-
-use C4::Context;
-use C4::Biblio;
-use C4::Items;
-use C4::Reserves;
-
-use Koha::Database;
-
-
-
-my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
-my $builder = t::lib::TestBuilder->new();
-
-my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
-my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
-my $borrower = $builder->build({
- source => 'Borrower',
- value => {
- branchcode => $branchcode,
- categorycode => $categorycode
- }
-});
-my $borrowernumber = $borrower->{borrowernumber};
-
-my $biblio = $builder->build( { source => 'Biblio', } );
-my $biblionumber = $biblio->{biblionumber};
-
-# Use AddReserve instead of TestBuilder because i don't manage
-# to make TestBuilder set hold_group_id to null. Idea ?
-my $reserve_id = AddReserve($branchcode, $borrowernumber,
-$biblionumber, $biblionumber, 1, undef, undef, undef
-$biblio->{title}, undef, undef, undef);
-
-is(GetHoldCount($borrowernumber), 1, 'Test borrower has 1 reserve.');
-
-my $reserves_group = $builder->build({
- source => 'HoldGroup',
- value => {
- hold_group_id => 1
- }
-});
-
-my $reserve2 = $builder->build({
- source => 'Reserve',
- value => {
- borrowernumber => $borrowernumber,
- hold_group_id => 1
- }
-});
-my $reserve3 = $builder->build({
- source => 'Reserve',
- value => {
- borrowernumber => $borrowernumber,
- hold_group_id => 1
- }
-});
-
-is(GetHoldCount($borrowernumber), 2, 'Test borrower has 2 reserve.');
-
-my $reserves_group2 = $builder->build({
- source => 'HoldGroup',
- value => {
- hold_group_id => 2
- }
-});
-my $hold_group_id2 = $reserves_group2->{hold_group_id};
-
-my $reserve4 = $builder->build({
- source => 'Reserve',
- value => {
- borrowernumber => $borrowernumber,
- hold_group_id => 2
- }
-});
-my $reserve5 = $builder->build({
- source => 'Reserve',
- value => {
- borrowernumber => $borrowernumber,
- hold_group_id => 2
- }
-});
-my $reserve6 = $builder->build({
- source => 'Reserve',
- value => {
- borrowernumber => $borrowernumber,
- hold_group_id => 2
- }
-});
-
-is(GetHoldCount($borrowernumber), 3, 'Test borrower has 2 reserve.');
-
-$dbh->rollback;
--