From 221c01c30b733a687e1e6ec7bde9c9ecce7865eb Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 24 May 2017 08:52:27 -0400 Subject: [PATCH] Bug 15494 - Add _items_denied_renewal sub to C4:Circulation::CanBookBeRenewed --- C4/Circulation.pm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a439021..68e1d1a 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -54,7 +54,8 @@ use Koha::Holds; use Koha::RefundLostItemFeeRule; use Koha::RefundLostItemFeeRules; use Carp; -use List::MoreUtils qw( uniq ); +use List::MoreUtils qw( uniq any ); +use YAML qw/Load/; use Scalar::Util qw( looks_like_number ); use Date::Calc qw( Today @@ -2657,6 +2658,8 @@ sub CanBookBeRenewed { my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' ); return ( 0, 'onsite_checkout' ) if $itemissue->{onsite_checkout}; + return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item }); + $borrowernumber ||= $itemissue->{borrowernumber}; my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; @@ -4102,6 +4105,39 @@ sub _CalculateAndUpdateFine { } } +sub _item_denied_renewal { + my ($params) = @_; + + my $item = $params->{item}; + unless ($item) { carp "No item passed in!" && return } + + my $yaml = C4::Context->preference('ItemsDeniedRenewal'); + return () if (! $yaml =~ /\S/ ); + $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt + my $denyingrules; + eval { + $denyingrules = YAML::Load($yaml); + }; + if ($@) { + warn "Unable to parse ItemsDeniedRenewal syspref : $@"; + return (); + } + foreach my $field (keys %$denyingrules) { + my $val; + if (exists $item->{$field}) { + $val = $item->{$field}; + } + $val = '' unless defined $val; + # If the results matches the values in the yaml file + if (any { $val eq $_ } @{$denyingrules->{$field}}) { + # We return true if match found + return 1; + } + } + return 0; +} + + 1; __END__ -- 2.1.4