Bugzilla – Attachment 27089 Details for
Bug 11630
AgeRestrictionMarker doesn't handle marker immediately followed by age
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11630 [QA Followup] - Move code to subroutine, add unit tests
Bug-11630-QA-Followup---Move-code-to-subroutine-ad.patch (text/plain), 6.10 KB, created by
Kyle M Hall (khall)
on 2014-04-14 12:04:21 UTC
(
hide
)
Description:
Bug 11630 [QA Followup] - Move code to subroutine, add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2014-04-14 12:04:21 UTC
Size:
6.10 KB
patch
obsolete
>From 01ddb53942920a1ab9183f01f6e53d1a33f3ec24 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 14 Apr 2014 08:03:34 -0400 >Subject: [PATCH] Bug 11630 [QA Followup] - Move code to subroutine, add unit tests > >--- > C4/Circulation.pm | 106 +++++++++++--------- > t/db_dependent/Circulation/AgeRestrictionMarkers.t | 17 +++ > 2 files changed, 76 insertions(+), 47 deletions(-) > create mode 100644 t/db_dependent/Circulation/AgeRestrictionMarkers.t > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index cddab0a..91a5814 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -972,63 +972,37 @@ sub CanBookBeIssued { > } > } > } >- # >- # CHECK AGE RESTRICTION >- # > >+ ## 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 ' ', uc($bibvalues); >- >- # Search first occurence of one of the markers >- my @markers = split /\|/, uc($markers); >- my $index = 0; >- my $restrictionyear = 0; >- for my $value (@values) { >- $index ++; >- for my $marker (@markers) { >- $marker =~ s/^\s+//; #remove leading spaces >- $marker =~ s/\s+$//; #remove trailing spaces >- if ($marker eq $value) { >- if ($index <= $#values) { >- $restrictionyear += $values[$index]; >- } >- last; >- } elsif ($value =~ /^\Q$marker\E(\d+)$/) { >- # Perhaps it is something like "K16" (as in Finland) >- $restrictionyear += $1; >- last; >- } >+ my $markers = C4::Context->preference('AgeRestrictionMarker'); >+ my $bibvalues = $biblioitem->{'agerestriction'}; >+ my $restriction_age = 0; >+ >+ $restriction_age = GetAgeRestriction( $biblioitem->{'agerestriction'} ); >+ >+ if ( $restriction_age > 0 ) { >+ if ( $borrower->{'dateofbirth'} ) { >+ my @alloweddate = split /-/, $borrower->{'dateofbirth'}; >+ $alloweddate[0] += $restriction_age; >+ >+ #Prevent runime eror on leap year (invalid date) >+ if ( ( $alloweddate[1] == 2 ) && ( $alloweddate[2] == 29 ) ) { >+ $alloweddate[2] = 28; > } >- last if ($restrictionyear > 0); >- } > >- 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"; > } >- >- if ( Date_to_Days(Today) < Date_to_Days(@alloweddate) -1 ) { >- if (C4::Context->preference('AgeRestrictionOverride' )) { >- $needsconfirmation{AGE_RESTRICTION} = "$bibvalues"; >- } >- else { >- $issuingimpossible{AGE_RESTRICTION} = "$bibvalues"; >- } >+ else { >+ $issuingimpossible{AGE_RESTRICTION} = "$bibvalues"; > } > } > } > } > >-## check for high holds decreasing loan period >+ ## check for high holds decreasing loan period > my $decrease_loan = C4::Context->preference('decreaseLoanHighHolds'); > if ( $decrease_loan && $decrease_loan == 1 ) { > my ( $reserved, $num, $duration, $returndate ) = >@@ -3588,6 +3562,44 @@ sub IsItemIssued { > return $sth->fetchrow; > } > >+sub GetAgeRestriction { >+ my ($record_restrictions) = @_; >+ my $markers = C4::Context->preference('AgeRestrictionMarker'); >+ >+ # Split $record_restrictions to something like FSK 16 or PEGI 6 >+ my @values = split ' ', uc($record_restrictions); >+ return unless @values; >+ >+ # Search first occurence of one of the markers >+ my @markers = split /\|/, uc($markers); >+ return unless @markers; >+ >+ my $index = 0; >+ my $restriction_year = 0; >+ for my $value (@values) { >+ $index++; >+ for my $marker (@markers) { >+ $marker =~ s/^\s+//; #remove leading spaces >+ $marker =~ s/\s+$//; #remove trailing spaces >+ if ( $marker eq $value ) { >+ if ( $index <= $#values ) { >+ $restriction_year += $values[$index]; >+ } >+ last; >+ } >+ elsif ( $value =~ /^\Q$marker\E(\d+)$/ ) { >+ >+ # Perhaps it is something like "K16" (as in Finland) >+ $restriction_year += $1; >+ last; >+ } >+ } >+ last if ( $restriction_year > 0 ); >+ } >+ >+ return $restriction_year; >+} >+ > 1; > > __END__ >diff --git a/t/db_dependent/Circulation/AgeRestrictionMarkers.t b/t/db_dependent/Circulation/AgeRestrictionMarkers.t >new file mode 100644 >index 0000000..c06776a >--- /dev/null >+++ b/t/db_dependent/Circulation/AgeRestrictionMarkers.t >@@ -0,0 +1,17 @@ >+use Modern::Perl; >+use Test::More tests => 4; >+ >+use C4::Context; >+use C4::Circulation; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+C4::Context->set_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' ); >+ >+is ( C4::Circulation::GetAgeRestriction('FSK 16'), '16', 'FSK 16 returns 16' ); >+is ( C4::Circulation::GetAgeRestriction('PEGI 16'), '16', 'PEGI 16 returns 16' ); >+is ( C4::Circulation::GetAgeRestriction('Age 16'), '16', 'Age 16 returns 16' ); >+is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' ); >+ >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11630
:
24857
|
26996
|
27089
|
27156
|
27163
|
27164
|
27165