From a3e6454512eaefa351f6d288fb72f5578571e121 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 --- 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 85ec23f..a0be087 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1135,10 +1135,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 || @@ -1147,7 +1149,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 f3da6e2..ff40c1c 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 a3cb1a9..8b8d504 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; @@ -168,6 +170,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'} @@ -176,7 +179,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 9605cdd..8abeb9e 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 8252e50..3844411 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -660,6 +660,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { my $allow_onshelf_holds; 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 @@ -670,7 +671,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 1feaf57..b2799ea 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.1.4