BUG 7621 [ENH] Circulation: Match age restriction of title with borrower's age without using categories

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

New version implementing Paul's advice.
See Wiki http://wiki.koha-community.org/wiki/Age_restrictiotion

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
fix updatedatabase.pl

New fix updatedatabase.pl to apply to current master by Marc Veron veron@veron.ch
...and fixed missing curly bracket after merging updatedatabase.pl

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Marc Veron 2012-08-11 11:39:44 +02:00 committed by Paul Poulain
parent b6433ee60a
commit 01a7188d6a
7 changed files with 104 additions and 7 deletions

View file

@ -3319,7 +3319,8 @@ sub _koha_modify_biblioitem_nonmarc {
cn_suffix = ?, cn_suffix = ?,
cn_sort = ?, cn_sort = ?,
totalissues = ?, totalissues = ?,
ean = ? ean = ?,
agerestriction = ?
where biblioitemnumber = ? where biblioitemnumber = ?
"; ";
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
@ -3331,8 +3332,7 @@ sub _koha_modify_biblioitem_nonmarc {
$biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, $biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'},
$biblioitem->{'lccn'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'lccn'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'},
$biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, $biblioitem->{'totalissues'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, $biblioitem->{'totalissues'},
$biblioitem->{'ean'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'}, $biblioitem->{'biblioitemnumber'}
$biblioitem->{'biblioitemnumber'}
); );
if ( $dbh->errstr ) { if ( $dbh->errstr ) {
$error .= "ERROR in _koha_modify_biblioitem_nonmarc $query" . $dbh->errstr; $error .= "ERROR in _koha_modify_biblioitem_nonmarc $query" . $dbh->errstr;
@ -3384,7 +3384,8 @@ sub _koha_add_biblioitem {
cn_suffix = ?, cn_suffix = ?,
cn_sort = ?, cn_sort = ?,
totalissues = ?, totalissues = ?,
ean = ? ean = ?,
agerestriction = ?
"; ";
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
$sth->execute( $sth->execute(
@ -3395,7 +3396,7 @@ sub _koha_add_biblioitem {
$biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'}, $biblioitem->{'pages'}, $biblioitem->{'bnotes'}, $biblioitem->{'size'}, $biblioitem->{'place'},
$biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'lccn'}, $biblioitem->{'marc'}, $biblioitem->{'url'}, $biblioitem->{'biblioitems.cn_source'},
$biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'}, $biblioitem->{'cn_suffix'}, $cn_sort,
$biblioitem->{'totalissues'}, $biblioitem->{'ean'} $biblioitem->{'totalissues'}, $biblioitem->{'ean'}, $biblioitem->{'agerestriction'}
); );
my $bibitemnum = $dbh->{'mysql_insertid'}; my $bibitemnum = $dbh->{'mysql_insertid'};

View file

@ -44,7 +44,15 @@ use Data::Dumper;
use Koha::DateUtils; use Koha::DateUtils;
use Koha::Calendar; use Koha::Calendar;
use Carp; 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); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
BEGIN { BEGIN {
@ -941,6 +949,62 @@ sub CanBookBeIssued {
} }
} }
} }
#
# CHECK AGE RESTRICTION
#
# get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:"
my $markers = C4::Context->preference('AgeRestrictionMarker' );
my $bibvalues = $biblioitem->{'agerestriction'};
if (($markers)&&($bibvalues))
{
# Split $bibvalues to something like FSK 16 or PEGI 6
my @values = split ' ', $bibvalues;
# Search first occurence of one of the markers
my @markers = split /\|/, $markers;
my $index = 0;
my $take = -1;
for my $value (@values) {
$index ++;
for my $marker (@markers) {
$marker =~ s/^\s+//; #remove leading spaces
$marker =~ s/\s+$//; #remove trailing spaces
if (uc($marker) eq uc($value)) {
$take = $index;
last;
}
}
if ($take > -1) {
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 runime eror on leap year (invalid date)
if ((@alloweddate[1] == 2) && (@alloweddate[2] == 29)) {
@alloweddate[2] = 28;
}
if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) {
if (C4::Context->preference('AgeRestrictionOverride' )) {
$needsconfirmation{AGE_RESTRICTION} = "$bibvalues";
}
else {
$issuingimpossible{AGE_RESTRICTION} = "$bibvalues";
}
}
}
}
}
return ( \%issuingimpossible, \%needsconfirmation, \%alerts ); return ( \%issuingimpossible, \%needsconfirmation, \%alerts );
} }

View file

@ -178,6 +178,7 @@ CREATE TABLE `biblioitems` ( -- information related to bibliographic records in
`cn_item` varchar(10) default NULL, `cn_item` varchar(10) default NULL,
`cn_suffix` varchar(10) default NULL, `cn_suffix` varchar(10) default NULL,
`cn_sort` varchar(30) default NULL, `cn_sort` varchar(30) default NULL,
`agerestriction` varchar(255) default NULL,
`totalissues` int(10), `totalissues` int(10),
`marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML `marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML
PRIMARY KEY (`biblioitemnumber`), PRIMARY KEY (`biblioitemnumber`),
@ -650,6 +651,7 @@ CREATE TABLE `deletedbiblioitems` ( -- information about bibliographic records t
`cn_item` varchar(10) default NULL, `cn_item` varchar(10) default NULL,
`cn_suffix` varchar(10) default NULL, `cn_suffix` varchar(10) default NULL,
`cn_sort` varchar(30) default NULL, `cn_sort` varchar(30) default NULL,
`agerestriction` varchar(255) default NULL,
`totalissues` int(10), `totalissues` int(10),
`marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML `marcxml` longtext NOT NULL, -- full bibliographic MARC record in MARCXML
PRIMARY KEY (`biblioitemnumber`), PRIMARY KEY (`biblioitemnumber`),

View file

@ -369,3 +369,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSuppressionByIPRange','','Restrict the suppression to IP adresses outside of the IP range','','free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSuppressionByIPRange','','Restrict the suppression to IP adresses outside of the IP range','','free');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('PrefillItem','0','When a new item is added, should it be prefilled with last created item values?','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('PrefillItem','0','When a new item is added, should it be prefilled with last created item values?','','YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionMarker','','Markers for age restriction indication, e.g. FSK|PEGI|Age|',NULL,'free');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionOverride',0,'Allow staff to check out an item with age restriction.',NULL,'YesNo');

View file

@ -5681,6 +5681,18 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
"INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free'); "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
"); ");
print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToUseWhenPrefill sysprefs)\n"; print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToUseWhenPrefill sysprefs)\n";
}
$DBversion = "3.09.00.036";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
# biblioitems changes
$dbh->do("ALTER TABLE biblioitems ADD COLUMN agerestriction VARCHAR(255) DEFAULT NULL AFTER cn_sort");
$dbh->do("ALTER TABLE deletedbiblioitems ADD COLUMN agerestriction VARCHAR(255) DEFAULT NULL AFTER cn_sort");
# preferences changes
$dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionMarker','','Markers for age restriction indication, e.g. FSK|PEGI|Age|. See: http://wiki.koha-community.org/wiki/Age_restriction',NULL,'free')");
$dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionOverride',0,'Allow staff to check out an item with age restriction.',NULL,'YesNo')");
print "Upgrade to $DBversion done (Add colum agerestriction to biblioitems and deletedbiblioitems, add system preferences AgeRestrictionMarker and AgeRestrictionOverride)\n";
SetVersion($DBversion); SetVersion($DBversion);
} }
@ -5766,4 +5778,3 @@ sub SetVersion {
C4::Context::clear_syspref_cache(); # invalidate cached preferences C4::Context::clear_syspref_cache(); # invalidate cached preferences
} }
exit; exit;

View file

@ -214,6 +214,15 @@ Circulation:
yes: "Don't prevent" yes: "Don't prevent"
no: "Prevent" no: "Prevent"
- patrons from checking out an item whose rental charge would take them over the limit. - patrons from checking out an item whose rental charge would take them over the limit.
-
- pref: AgeRestrictionMarker
- "E.g. FSK|PEGI|Age| (No white space near |). Entry in MARC field (e.g. 521a) as defined for agerestriction in Koha to MARC mapping. Entry in MARC field like FSK 12 or PEGI 12 would mean: Borrower must be 12 years old. (Empty: Do not apply age restriction.)"
-
- pref: AgeRestrictionOverride
choices:
yes: Allow
no: "Don't allow"
- staff to check out an item with age restriction.
- -
- Prevent patrons from checking out books if they have more than - Prevent patrons from checking out books if they have more than
- pref: noissuescharge - pref: noissuescharge

View file

@ -250,6 +250,10 @@ function validate1(date) {
<h3>Please confirm checkout</h3> <h3>Please confirm checkout</h3>
<ul> <ul>
[%IF ( AGE_RESTRICTION ) %]
<li>Age restriction [% AGE_RESTRICTION %]. Check out anyway?</li>
[% END %]
[% IF ( DEBT ) %] [% IF ( DEBT ) %]
<li>The patron has a debt of [% DEBT %]</li> <li>The patron has a debt of [% DEBT %]</li>
[% END %] [% END %]
@ -401,6 +405,10 @@ function validate1(date) {
<li>No more renewals possible</li> <li>No more renewals possible</li>
[% END %] [% END %]
[%IF ( AGE_RESTRICTION ) %]
<li>Age restriction [% AGE_RESTRICTION %].</li>
[% END %]
[% IF ( EXPIRED ) %] [% IF ( EXPIRED ) %]
<li>Patron's card is expired</li> <li>Patron's card is expired</li>
[% END %] [% END %]