@@ -, +, @@ Koha/Biblio --- C4/Reserves.pm | 34 ------------------ Koha/Biblio.pm | 31 +++++++++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-reserve.tt | 40 ++++++++++++++-------- opac/opac-reserve.pl | 4 ++- reserve/request.pl | 5 ++- t/db_dependent/Reserves/MultiplePerRecord.t | 9 +++-- 6 files changed, 69 insertions(+), 54 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -140,7 +140,6 @@ BEGIN { IsItemOnHoldAndFound GetMaxPatronHoldsForRecord - GetAllowedHoldsForPatronToday ); @EXPORT_OK = qw( MergeHolds ); } @@ -2122,39 +2121,6 @@ sub GetMaxPatronHoldsForRecord { return $max; } -=head2 GetAllowedHoldsForPatronToday - -my $holds_allowed_on_record_today = GetAllowedHoldsForPatronToday( $patron->borrowernumber, $biblionumber ); - -Calculates and returns the number of item-level holds a borrower is allowed to place on the record on a single day. - -=cut - -sub GetAllowedHoldsForPatronToday { - my ( $borrowernumber, $biblionumber ) = @_; - - my $patron = Koha::Patrons->find($borrowernumber); - my @items = Koha::Items->search( { biblionumber => $biblionumber } ); - - my $controlbranch = C4::Context->preference('ReservesControlBranch'); - - my $categorycode = $patron->categorycode; - my $branchcode; - $branchcode = $patron->branchcode if ( $controlbranch eq "PatronLibrary" ); - - my $holds_allowed = 0; - foreach my $item (@items) { - my $itemtype = $item->effective_itemtype(); - - $branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); - - my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); - my $holds_per_day = $rule ? $rule->{holds_per_day} : 0; - $holds_allowed = $holds_per_day if $holds_per_day > $holds_allowed; - } - return $holds_allowed; -} - =head2 GetHoldRule my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -425,6 +425,37 @@ sub has_items_waiting_or_intransit { return 0; } +=head3 allowed_holds + + my $holds_allowed_on_record_today = $biblio->allowed_holds( $patron_obj ); + + Calculates and returns the number of item-level holds a borrower is allowed to place on the record on a single day. + +=cut + +sub allowed_holds { + my ( $self, $patron ) = @_; + + my $controlbranch = C4::Context->preference('ReservesControlBranch'); + + my $categorycode = $patron->categorycode; + my $branchcode; + $branchcode = $patron->branchcode if ( $controlbranch eq "PatronLibrary" ); + + my $holds_allowed = 0; + foreach my $item ( $self->items()->as_list() ) { + my $itemtype = $item->effective_itemtype(); + $branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); + + my $rule = C4::Reserves::GetHoldRule( $categorycode, $itemtype, $branchcode ); + my $holds_per_day = $rule ? $rule->{holds_per_day} : 0; + if ( $holds_per_day ) { + $holds_allowed = $holds_per_day if $holds_per_day > $holds_allowed; + } + } + return $holds_allowed; +} + =head3 type =cut --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -463,7 +463,9 @@