From 061c594c57e0bb558dc0ab0ca1e0d9ffe4e24e64 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 Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b915b34..cf09b37 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -55,7 +55,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 @@ -2607,6 +2608,8 @@ sub CanBookBeRenewed { my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' ); return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout; + return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item }); + $borrowernumber ||= $issue->borrowernumber; my $patron = Koha::Patrons->find( $borrowernumber ) or return; @@ -4062,6 +4065,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