View | Details | Raw Unified | Return to bug 11630
Collapse All | Expand All

(-)a/C4/Circulation.pm (-47 / +59 lines)
Lines 972-1034 sub CanBookBeIssued { Link Here
972
            }
972
            }
973
        }
973
        }
974
    }
974
    }
975
    #
976
    # CHECK AGE RESTRICTION
977
    #
978
975
976
    ## CHECK AGE RESTRICTION
979
    # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:"
977
    # get $marker from preferences. Could be something like "FSK|PEGI|Alter|Age:"
980
    my $markers = C4::Context->preference('AgeRestrictionMarker' );
978
    my $markers         = C4::Context->preference('AgeRestrictionMarker');
981
    my $bibvalues = $biblioitem->{'agerestriction'};
979
    my $bibvalues       = $biblioitem->{'agerestriction'};
982
    if (($markers)&&($bibvalues))
980
    my $restriction_age = 0;
983
    {
981
984
        # Split $bibvalues to something like FSK 16 or PEGI 6
982
    $restriction_age = GetAgeRestriction( $biblioitem->{'agerestriction'} );
985
        my @values = split ' ', uc($bibvalues);
983
986
984
    if ( $restriction_age > 0 ) {
987
        # Search first occurence of one of the markers
985
        if ( $borrower->{'dateofbirth'} ) {
988
        my @markers = split /\|/, uc($markers);
986
            my @alloweddate = split /-/, $borrower->{'dateofbirth'};
989
        my $index = 0;
987
            $alloweddate[0] += $restriction_age;
990
        my $restrictionyear = 0;
988
991
        for my $value (@values) {
989
            #Prevent runime eror on leap year (invalid date)
992
            $index ++;
990
            if ( ( $alloweddate[1] == 2 ) && ( $alloweddate[2] == 29 ) ) {
993
            for my $marker (@markers) {
991
                $alloweddate[2] = 28;
994
                $marker =~ s/^\s+//; #remove leading spaces
995
                $marker =~ s/\s+$//; #remove trailing spaces
996
                if ($marker eq $value) {
997
                    if ($index <= $#values) {
998
                        $restrictionyear += $values[$index];
999
                    }
1000
                    last;
1001
                } elsif ($value =~ /^\Q$marker\E(\d+)$/) {
1002
                    # Perhaps it is something like "K16" (as in Finland)
1003
                    $restrictionyear += $1;
1004
                    last;
1005
                }
1006
            }
992
            }
1007
            last if ($restrictionyear > 0);
1008
        }
1009
993
1010
        if ($restrictionyear > 0) {
994
            if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) - 1 ) {
1011
            if ( $borrower->{'dateofbirth'}  ) {
995
                if ( C4::Context->preference('AgeRestrictionOverride') ) {
1012
                my @alloweddate =  split /-/,$borrower->{'dateofbirth'} ;
996
                    $needsconfirmation{AGE_RESTRICTION} = "$bibvalues";
1013
                $alloweddate[0] += $restrictionyear;
1014
                #Prevent runime eror on leap year (invalid date)
1015
                if (($alloweddate[1] == 2) && ($alloweddate[2] == 29)) {
1016
                    $alloweddate[2] = 28;
1017
                }
997
                }
1018
998
                else {
1019
                if ( Date_to_Days(Today) <  Date_to_Days(@alloweddate) -1  ) {
999
                    $issuingimpossible{AGE_RESTRICTION} = "$bibvalues";
1020
                    if (C4::Context->preference('AgeRestrictionOverride' )) {
1021
                        $needsconfirmation{AGE_RESTRICTION} = "$bibvalues";
1022
                    }
1023
                    else {
1024
                        $issuingimpossible{AGE_RESTRICTION} = "$bibvalues";
1025
                    }
1026
                }
1000
                }
1027
            }
1001
            }
1028
        }
1002
        }
1029
    }
1003
    }
1030
1004
1031
## check for high holds decreasing loan period
1005
    ## check for high holds decreasing loan period
1032
    my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds');
1006
    my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds');
1033
    if ( $decrease_loan && $decrease_loan == 1 ) {
1007
    if ( $decrease_loan && $decrease_loan == 1 ) {
1034
        my ( $reserved, $num, $duration, $returndate ) =
1008
        my ( $reserved, $num, $duration, $returndate ) =
Lines 3588-3593 sub IsItemIssued { Link Here
3588
    return $sth->fetchrow;
3562
    return $sth->fetchrow;
3589
}
3563
}
3590
3564
3565
sub GetAgeRestriction {
3566
    my ($record_restrictions) = @_;
3567
    my $markers = C4::Context->preference('AgeRestrictionMarker');
3568
3569
    # Split $record_restrictions to something like FSK 16 or PEGI 6
3570
    my @values = split ' ', uc($record_restrictions);
3571
    return unless @values;
3572
3573
    # Search first occurence of one of the markers
3574
    my @markers = split /\|/, uc($markers);
3575
    return unless @markers;
3576
3577
    my $index            = 0;
3578
    my $restriction_year = 0;
3579
    for my $value (@values) {
3580
        $index++;
3581
        for my $marker (@markers) {
3582
            $marker =~ s/^\s+//;    #remove leading spaces
3583
            $marker =~ s/\s+$//;    #remove trailing spaces
3584
            if ( $marker eq $value ) {
3585
                if ( $index <= $#values ) {
3586
                    $restriction_year += $values[$index];
3587
                }
3588
                last;
3589
            }
3590
            elsif ( $value =~ /^\Q$marker\E(\d+)$/ ) {
3591
3592
                # Perhaps it is something like "K16" (as in Finland)
3593
                $restriction_year += $1;
3594
                last;
3595
            }
3596
        }
3597
        last if ( $restriction_year > 0 );
3598
    }
3599
3600
    return $restriction_year;
3601
}
3602
3591
1;
3603
1;
3592
3604
3593
__END__
3605
__END__
(-)a/t/db_dependent/Circulation/AgeRestrictionMarkers.t (-1 / +17 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Test::More tests => 4;
3
4
use C4::Context;
5
use C4::Circulation;
6
7
my $dbh = C4::Context->dbh;
8
$dbh->{AutoCommit} = 0;
9
$dbh->{RaiseError} = 1;
10
11
C4::Context->set_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' );
12
13
is ( C4::Circulation::GetAgeRestriction('FSK 16'), '16', 'FSK 16 returns 16' );
14
is ( C4::Circulation::GetAgeRestriction('PEGI 16'), '16', 'PEGI 16 returns 16' );
15
is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' );
16
is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' );
17

Return to bug 11630