From bcad390a72e70867316d8c7d2fca38003b0d1a66 Mon Sep 17 00:00:00 2001 From: Marc Veron Date: Mon, 16 Jul 2012 07:11:06 +0200 Subject: [PATCH] Bug 7621 . Circulation: Match age restriction of title with borrower's age without using categories Content-Type: text/plain; charset="utf-8" Signed-off-by: Chris Cormack New version implementing Paul's advice. Usage see http://wiki.koha-community.org/wiki/Age_restriction Changes in C4/Circulation.pm; - skip age restriciton part as well if no age restriction info in biblio record - more robust string comparision part (nested for... loops instead of grep and better handling of superfluous white space) - display whole age restriction string as information (e.g. FSK 16 instead of 16) --- C4/Circulation.pm | 30 +++++++++++++++++++----------- 1 files changed, 19 insertions(+), 11 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 55f8988..d826161 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -944,21 +944,28 @@ sub CanBookBeIssued { # # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:" - my $marker = C4::Context->preference('AgeRestrictionMarker' ); - if ($marker) + my $markers = C4::Context->preference('AgeRestrictionMarker' ); + my $agerestriction = $biblioitem->{'agerestriction'}; + if ($markers && $agerestriction) { # Split $value to something like FSK 16 or PEGI 6 - my @marker = split /\|/, $marker; - my @values = split ' ', $biblioitem->{'agerestriction'} ; - + my @markers = split /\|/, $markers; + my @values = split ' ', $agerestriction; # Search first occurence of one of the markers my $index = 0; my $take = -1; for my $value (@values) { - $index ++; - if (grep {uc($_) eq $value} @marker) { - $take = $index; + $index = $index +1 ; + for my $marker (@markers) { + $marker =~ s/^\s+//; #remove leading spaces + $marker =~ s/\s+$//; #remove trailing spaces + if ($marker eq $value) { + $take = $index; + last; + } + } + if ($take > -1) { last; } } @@ -972,7 +979,7 @@ sub CanBookBeIssued { if ( $borrower->{'dateofbirth'} ) { my @alloweddate = split /-/,$borrower->{'dateofbirth'} ; @alloweddate[0] += $restrictionyear; - #Prevent runime eror on leap year (invalid date) + #Prevent runtime eror on leap year (invalid date) if ((@alloweddate[1] == 2) && (@alloweddate[2] == 29)) { @alloweddate[2] = 28; } @@ -982,15 +989,16 @@ sub CanBookBeIssued { if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) { if (C4::Context->preference('AgeRestrictionOverride ' )) { - $needsconfirmation{AGE_RESTRICTION} = "$restrictionyear"; + $needsconfirmation{AGE_RESTRICTION} = "$agerestriction"; } else { - $issuingimpossible{AGE_RESTRICTION} = "$restrictionyear"; + $issuingimpossible{AGE_RESTRICTION} = "$agerestriction"; } } } } } + return ( \%issuingimpossible, \%needsconfirmation, \%alerts ); } -- 1.7.2.5