From ac2cf5f0120bd53111cfeef9488b75119157c268 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Mon, 12 Nov 2018 09:51:18 +0000 Subject: [PATCH] Bug 15565: (follow-up) Moved function form C4/Reserves to Koha/Biblio Also updated t/db_dependen/Reserves/MultiplePerRecord.t test to reflect moving function. Added the display of the JS modal box informing OPAC borrower that they have exceeded hold limit after they click 'A specific item' radiobutton on opac-reserve if holds per day, holds per record or maxreserves is 1 Test plan: 1. Apply patches 2. Restart memcached and plack 3. Run t/db_dependent/Reserves/MultiplePerRecord.t 4. Set your maxreserves syspref to 3, and a circ rules holds per record to 2 and holds per day to 1 5. In the OPAC visit the 'Place hold' interface of item. Select the 'A specific item' radiobutton and observe a modal box loads to inform you that you have reached the maximum holds allowed today. 6. Click 'OK' on the modal and notice the first checkbox is selected and other unchecked checkboxes are disabled. 7. Repeat step 4 this time setting holds per day to 5 8. Now reloading the OPAC 'Place hold' page notice after clicking 'A specific item' no modal displays and select another item checkbox (so you have 2 selected checkboxes). Observe a modal saying you have reached the maximum number of holds for the record is loaded 9. Click 'OK' on modal and observe all unchecked item checkboxes are automatically disabled to prevent additional holds being placed 10. Select 'Confirm hold' 11. On your holds summary page confirm both holds are placed 12. In the staff client set the 'AllowHoldPolicyOverride' syspref to "Don't allow" 13. Visit a biblio reservation interface in the staff client 14. Select 2 item checkboxes and observe the modal box explaining you have reached maximum holds for the record is displayed. 15. Select 'OK' on the modal and notice all un-checked item checkboxes are automatically disabled 16. Repeat steps 12-15 this time with the value of 'AllowHoldPolicyOverride' syspref set to 'Allow' and notice that once you have clicked on the second item checkbox although the modal still loads the item checkboxes do not disable - you are able to override and continue selecting checkboxes each time with modal warning loading. 17. Observe the allow_holds() function is in the Koha/Biblio.pm file and the GetAllowedHoldsForPatronToday() function has been removed from C4/Reserves.pm Sponsored-By: Brimbank Library, Australia --- 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(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 15b79a5..77e4213 100644 --- a/C4/Reserves.pm +++ b/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 ); diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 1dca4d9..5bd7fe0 100644 --- a/Koha/Biblio.pm +++ b/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 => $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 diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt index e46609f..57c5bf8 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -463,7 +463,9 @@