From 39e1fbcbe95eb128dc9e6eb78df2ea2f0c68ff0f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Sep 2017 16:02:19 -0300 Subject: [PATCH] Bug 19301: Move C4::Reserves::OnShelfHoldsAllowed to get_onshelfholds_policy Following the pattern introduced by bug 19300, we are going to move the OnShelfHoldsAllowed logic to Koha::IssuingRules->get_onshelfholds_policy Test plan: Make sure the onshelfholds policy is correct when placing a hold Signed-off-by: Alex Buckley Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/Reserves.pm | 8 +++++--- Koha/IssuingRules.pm | 15 +++++++++++++++ opac/opac-ISBDdetail.pl | 5 ++++- opac/opac-MARCdetail.pl | 3 ++- opac/opac-detail.pl | 3 ++- opac/opac-shelves.pl | 3 ++- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 31fc97e3a9..4f8d16e3c6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1101,10 +1101,12 @@ sub IsAvailableForItemLevelRequest { # FIXME - a lot of places in the code do this # or something similar - need to be # consolidated - my $itype = _get_itype($item); + my $patron = Koha::Patrons->find( $borrower->{borrowernumber} ); + my $item_object = Koha::Items->find( $item->{itemnumber } ); + my $itemtype = $item_object->effective_itemtype; my $notforloan_per_itemtype = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?", - undef, $itype); + undef, $itemtype); return 0 if $notforloan_per_itemtype || @@ -1113,7 +1115,7 @@ sub IsAvailableForItemLevelRequest { $item->{withdrawn} || ($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems')); - my $on_shelf_holds = _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch}); + my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } ); if ( $on_shelf_holds == 1 ) { return 1; diff --git a/Koha/IssuingRules.pm b/Koha/IssuingRules.pm index f3da6e21e8..ff40c1c874 100644 --- a/Koha/IssuingRules.pm +++ b/Koha/IssuingRules.pm @@ -100,6 +100,21 @@ sub get_opacitemholds_policy { return $issuing_rule ? $issuing_rule->opacitemholds : undef; } +sub get_onshelfholds_policy { + my ( $class, $params ) = @_; + my $item = $params->{item}; + my $itemtype = $item->effective_itemtype; + my $patron = $params->{patron}; + my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( + { + ( $patron ? ( categorycode => $patron->categorycode ) : () ), + itemtype => $itemtype, + branchcode => $item->holdingbranch + } + ); + return $issuing_rule ? $issuing_rule->onshelfholds : undef; +} + =head3 type =cut diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index b4353ba6ff..40e9b71f4c 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -52,6 +52,8 @@ use C4::Reserves; use C4::Acquisition; use C4::Serials; # uses getsubscriptionfrom biblionumber use C4::Koha; +use Koha::IssuingRules; +use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use Koha::RecordProcessor; @@ -169,6 +171,7 @@ my $res = GetISBDView({ my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; my $patron = Koha::Patrons->find( $loggedinuser ); for my $itm (@items) { + my $item = Koha::Items->find( $itm->{itemnumber} ); $norequests = 0 if $norequests && !$itm->{'withdrawn'} @@ -177,7 +180,7 @@ for my $itm (@items) { && !$itemtypes->{$itm->{'itype'}}->{notforloan} && $itm->{'itemnumber'}; - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) ) + $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; } diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 609d9d964e..c44c5df2bb 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -132,7 +132,8 @@ if(my $cart_list = $query->cookie("bib_list")){ my $allow_onshelf_holds; my $patron = Koha::Patrons->find( $loggedinuser ); for my $itm (@all_items) { - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) ); + my $items = Koha::Items->find( $itm->{itemnumber} ); + $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); last if $allow_onshelf_holds; } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index ea7d04594b..81edc1533e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -661,6 +661,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { } else { my $patron = Koha::Patrons->find( $borrowernumber ); for my $itm (@items) { + my $item = Koha::Items->find( $itm->{itemnumber} ); $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; $itm->{priority} = $priority{ $itm->{itemnumber} }; $norequests = 0 @@ -671,7 +672,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { && !$itemtypes->{$itm->{'itype'}}->{notforloan} && $itm->{'itemnumber'}; - $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) ) + $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ) unless $allow_onshelf_holds; # get collection code description, too diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 1feaf57cae..b2799ea023 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -31,6 +31,7 @@ use C4::XSLT; use Koha::Biblios; use Koha::Biblioitems; +use Koha::IssuingRules; use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; @@ -319,7 +320,7 @@ if ( $op eq 'view' ) { my $items = $biblio->items; while ( my $item = $items->next ) { - $this_item->{allow_onshelf_holds} = C4::Reserves::OnShelfHoldsAllowed($item->unblessed, $patron); + $this_item->{allow_onshelf_holds} = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); last if $this_item->{allow_onshelf_holds}; } -- 2.39.5