From 633a587213ba59b977d8aa1a2f69f6307ceafae2 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: Marcel de Rooy Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- C4/Circulation.pm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 23d0b5fb5c..a929c6ca25 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -58,7 +58,7 @@ use Koha::RefundLostItemFeeRules; use Koha::Account::Lines; use Koha::Account::Offsets; use Carp; -use List::MoreUtils qw( uniq ); +use List::MoreUtils qw( uniq any ); use Scalar::Util qw( looks_like_number ); use Date::Calc qw( Today @@ -2617,6 +2617,8 @@ sub CanBookBeRenewed { my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); 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 ) @@ -4122,6 +4124,40 @@ sub _CalculateAndUpdateFine { } } +sub _item_denied_renewal { + my ($params) = @_; + + my $item = $params->{item}; + return unless $item; + + my $yaml = C4::Context->preference('ItemsDeniedRenewal'); + my @lines = split /\n/, $yaml; + my $denyingrules; + foreach my $line (@lines){ + my ($field,$array) = split /:/, $line; + $array =~ s/[ [\]\r]//g; + my @array = split /,/, $array; + @array = map { $_ eq 'NULL' ? undef : $_ } @array; + @array = map { $_ eq '""' || $_ eq "''" ? undef : $_ } @array; + $denyingrules->{$field} = \@array; + } + return unless $denyingrules; + foreach my $field (keys %$denyingrules) { + my $val = $item->{$field}; + if( !defined $val) { + if ( any { !defined $_ } @{$denyingrules->{$field}} ){ + return 1; + } + } elsif (any { $val eq $_ } @{$denyingrules->{$field}}) { + # If the results matches the values in the syspref + # We return true if match found + return 1; + } + } + return 0; +} + + 1; __END__ -- 2.39.5