From 9dc4cb99fce800b0e8ee18a06ddc1e771e5991ef Mon Sep 17 00:00:00 2001 From: mveron Date: Fri, 13 Apr 2012 14:52:26 +0200 Subject: [PATCH] Bug 7621 [ENH]- Circulation: Match age restriction of title with borrower's age without using categories Content-Type: text/plain; charset="utf-8" Test scenario: 1) Edit preferences Circulation: AgeRestrictionField (521), AgeRestrictionSubField (a), AgeRestrictionMarker (FSK|PEGI|Age) and AgeRestrictionOverride (Prevent or Dont prevent) 2) Create a young patron account e.g. with age < 16 3) Create or edit a biblio with e.g. the value FSK 16 in the field 521a 4) Try to check out to young patron 5) Chckout should be blocked or issue a warning with override (depending on AgeRestrictionOverride) --- C4/Circulation.pm | 87 ++++++++++++++++++++ .../en/modules/admin/preferences/circulation.pref | 13 +++ .../prog/en/modules/circ/circulation.tt | 8 ++ 3 files changed, 108 insertions(+), 0 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 6ca860d..4b6f632 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -41,6 +41,15 @@ use Data::Dumper; use Koha::DateUtils; use Koha::Calendar; use Carp; +use Date::Calc qw( + Today + Today_and_Now + Add_Delta_YM + Add_Delta_DHMS + Date_to_Days + Day_of_Week + Add_Delta_Days +); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -926,6 +935,84 @@ sub CanBookBeIssued { } } } + + # + # CHECK AGE RESTRICTION ON TITLE + # + + # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:" + my $marker = C4::Context->preference('AgeRestrictionMarker' ); + my $xmlfield = C4::Context->preference('AgeRestrictionField' ); + my $xmlsubfield = C4::Context->preference('AgeRestrictionSubField' ); + + if (($marker) && ($xmlfield)) + { + my $thesql; + if ($xmlsubfield) { + $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + '//datafield[\@tag=\"${xmlfield}\"]/subfield[\@code=\"${xmlsubfield}\"]') AS mycode;"; + } else { + $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + '//datafield[\@tag=\"${xmlfield}\"]]') AS mycode;"; + } + + #Hard coded version + #my $thesql = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber=?), + # '//datafield[\@tag=\"521\"]/subfield[\@code=\"a\"]') AS mycode;"; + + my $mysth = $dbh->prepare($thesql); + $mysth->execute( $item->{'itemnumber'} ); + my $iteminfo = $mysth->fetchrow_hashref; + $mysth->finish; + + my $values = uc( $iteminfo->{'mycode'} ); + + my @marker = split /\|/, $marker; + + # Split $value Something like FSK 16 or PEGI 6 + my @values = split ' ', $values ; + + # Search first occurence of one of the labels + my $index = 0; + my $take = -1; + for my $value (@values) { + $index ++; + if (grep {uc($_) eq $value} @marker) { + $take = $index; + last; + } + } + + # Index points to the next value + my $restrictionyear = 0; + if (($take <= $#values) && ($take >= 0)){ + $restrictionyear += @values[$take]; + } + + if ($restrictionyear > 0) { + if ( $borrower->{'dateofbirth'} ) { + my @alloweddate = split /-/,$borrower->{'dateofbirth'} ; + @alloweddate[0] += $restrictionyear; + #Prevent runtime eror on leap year (invalid date) + if ((@alloweddate[1] == 02) && (@alloweddate[2] == 29)) { + @alloweddate[2] = 28; + } + + my $td = Date_to_Days(Today); + my $ad = Date_to_Days(@alloweddate); + + if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) { + if (C4::Context->preference('AgeRestrictionOverride ' )) { + $issuingimpossible{AGE_RESTRICTION} = "$restrictionyear"; + } + else { + $needsconfirmation{AGE_RESTRICTION} = "$restrictionyear"; + } + } + } + } + } + return ( \%issuingimpossible, \%needsconfirmation ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 471aa0e..ac7c23a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -208,6 +208,19 @@ Circulation: no: "Don't prevent" - patrons from checking out an item whose rental charge would take them over the limit. - + - pref: AgeRestrictionField + - pref: AgeRestrictionSubField + - "Marc field / subfield for age restriction. E.g. 521 a (Empty AgeRestrictionField - Do not apply age restriction)" + - + - pref: AgeRestrictionMarker + - "E.g. FSK|PEGI|Age| (No white space near |). Entry in Marc field e.g. PEGI 6 (Empty - Do not apply age restriction)" + - + - pref: AgeRestrictionOverride + choices: + yes: Prevent + no: "Don't prevent" + - patrons from checking out an item whose age restriction would apply. + - - Prevent patrons from checking out books if they have more than - pref: noissuescharge class: integer diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index e79cef1..174b1f6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -240,6 +240,10 @@ function refocus(calendar) {

Please confirm checkout