summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-12-17 14:39:41 +0100
committerYorhel <git@yorhel.nl>2010-12-17 14:48:04 +0100
commit50cfb305796d1d115c408feefbe39fddf7615166 (patch)
treec56da35435063a11b79837dfd8821f6a63719271 /lib/VNDB
parenteaf9e895daab98eb122f2570bb409794b3257c99 (diff)
Don't allow NULL for rr.minage and use -1 for unknown
This can be seen as a partial revert of 0a4f97f0186d6941a4cab2e3bd05201f1fed1441. I used to think using NULL for special values is more "correct" in database terms. But in the end I guess I should be aiming for whatever solution is easier. Both are "correct" in a sense anyway.
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/DB/Releases.pm11
-rw-r--r--lib/VNDB/Func.pm2
-rw-r--r--lib/VNDB/Handler/Producers.pm2
-rw-r--r--lib/VNDB/Handler/Releases.pm18
-rw-r--r--lib/VNDB/Handler/VNPage.pm2
5 files changed, 12 insertions, 23 deletions
diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm
index b0fb9a89..ffffb2a6 100644
--- a/lib/VNDB/DB/Releases.pm
+++ b/lib/VNDB/DB/Releases.pm
@@ -32,6 +32,7 @@ sub dbReleaseGet {
defined $o{type} ? ( 'rr.type = ?' => $o{type} ) : (),
defined $o{date_before} ? ( 'rr.released <= ?' => $o{date_before} ) : (),
defined $o{date_after} ? ( 'rr.released >= ?' => $o{date_after} ) : (),
+ defined $o{minage} ? ( 'rr.minage IN(!l)' => [ ref $o{minage} ? $o{minage} : [$o{minage}] ] ) : (),
defined $o{resolution} ? ( 'rr.resolution IN(!l)' => [ ref $o{resolution} ? $o{resolution} : [$o{resolution}] ] ) : (),
defined $o{voiced} ? ( 'rr.voiced IN(!l)' => [ ref $o{voiced} ? $o{voiced} : [$o{voiced}] ] ) : (),
defined $o{ani_story} ? ( 'rr.ani_story IN(!l)' => [ ref $o{ani_story} ? $o{ani_story} : [$o{ani_story}] ] ) : (),
@@ -47,16 +48,6 @@ sub dbReleaseGet {
'rr.id IN(SELECT irm.rid FROM releases_media irm JOIN releases ir ON ir.latest = irm.rid WHERE irm.medium IN(!l))' => [ ref $o{med} ? $o{med} : [ $o{med} ] ] ) : (),
);
- # TODO: don't allow NULL for rr.minage after all, since this could be a lot easier...
- if(exists $o{minage}) {
- my @m = ref $o{minage} ? @{$o{minage}} : ($o{minage});
- my @w = (
- grep(!defined $_ || $_ == -1, @m) ? 'rr.minage IS NULL' : (),
- grep(defined $_ && $_ != -1, @m) ? 'rr.minage IN(!s)' : ()
- );
- push @where, '('.join(' OR ', @w).')', [ grep defined $_ && $_ != -1, @m ];
- }
-
if($o{search}) {
for (split /[ -,._]/, $o{search}) {
s/%//g;
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 65b66f9e..dcec9e8f 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -82,7 +82,7 @@ sub mt {
sub minage {
my($a, $ex) = @_;
- my $str = !defined($a) ? mt '_minage_null' : !$a ? mt '_minage_all' : mt '_minage_age', $a;
+ my $str = $a == -1 ? mt '_minage_null' : !$a ? mt '_minage_all' : mt '_minage_age', $a;
$ex = !defined($a) ? '' : {
0 => 'CERO A',
12 => 'CERO B',
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 6e11e829..d6308593 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -162,7 +162,7 @@ sub _releases {
for my $rel (@{$vn{$v->{vid}}}) {
Tr class => 'rel';
td class => 'tc1'; lit $self->{l10n}->datestr($rel->{released}); end;
- td class => 'tc2', !defined($rel->{minage}) ? '' : minage $rel->{minage};
+ td class => 'tc2', $rel->{minage} < 0 ? '' : minage $rel->{minage};
td class => 'tc3';
for (sort @{$rel->{platforms}}) {
next if $_ eq 'oth';
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index ce5c62c2..218389ee 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -190,7 +190,7 @@ sub _infotable {
end;
end;
- if(defined $r->{minage}) {
+ if($r->{minage} >= 0) {
Tr ++$i % 2 ? (class => 'odd') : ();
td mt '_relinfo_minage';
td minage $r->{minage};
@@ -287,9 +287,8 @@ sub edit {
my $vn = $rid ? $r->{vn} : [{ vid => $vid, title => $v->{title} }];
my %b4 = !$rid ? () : (
- (map { $_ => $r->{$_} } qw|type title original gtin catalog languages website released
+ (map { $_ => $r->{$_} } qw|type title original gtin catalog languages website released minage
notes platforms patch resolution voiced freeware doujin ani_story ani_ero ihid ilock|),
- minage => defined($r->{minage}) ? $r->{minage} : -1,
media => join(',', sort map "$_->{medium} $_->{qty}", @{$r->{media}}),
producers => join('|||', map
sprintf('%d,%d,%s', $_->{id}, ($_->{developer}?1:0)+($_->{publisher}?2:0), $_->{name}),
@@ -315,7 +314,7 @@ sub edit {
{ name => 'languages', multi => 1, enum => $self->{languages} },
{ name => 'website', required => 0, default => '', maxlength => 250, template => 'url' },
{ name => 'released', required => 0, default => 0, template => 'int' },
- { name => 'minage' , required => 0, default => -1, enum => [map !defined($_)?-1:$_, @{$self->{age_ratings}}] },
+ { name => 'minage' , required => 0, default => -1, enum => $self->{age_ratings} },
{ name => 'notes', required => 0, default => '', maxlength => 10240 },
{ name => 'platforms', required => 0, default => '', multi => 1, enum => $self->{platforms} },
{ name => 'media', required => 0, default => '' },
@@ -356,9 +355,8 @@ sub edit {
if(!$frm->{_err}) {
my $nrev = $self->dbItemEdit(r => !$copy && $rid ? $r->{cid} : undef,
- (map { $_ => $frm->{$_} } qw| type title original gtin catalog languages website released
+ (map { $_ => $frm->{$_} } qw| type title original gtin catalog languages website released minage
notes platforms resolution editsum patch voiced freeware doujin ani_story ani_ero ihid ilock|),
- minage => $frm->{minage} < 0 ? undef : $frm->{minage},
vn => $new_vn,
producers => $producers,
media => $media,
@@ -406,7 +404,7 @@ sub _form {
[ date => short => 'released', name => mt('_redit_form_released') ],
[ static => content => mt('_redit_form_released_note') ],
[ select => short => 'minage', name => mt('_redit_form_minage'),
- options => [ map [ !defined($_)?-1:$_, minage $_, 1 ], @{$self->{age_ratings}} ] ],
+ options => [ map [ $_, minage $_, 1 ], @{$self->{age_ratings}} ] ],
[ textarea => short => 'notes', name => mt('_redit_form_notes').'<br /><b class="standout">'.mt('_inenglish').'</b>' ],
[ static => content => mt('_redit_form_notes_note') ],
],
@@ -538,7 +536,7 @@ sub browse {
td class => 'tc1';
lit $self->{l10n}->datestr($l->{released});
end;
- td class => 'tc2', !defined($l->{minage}) ? '' : minage $l->{minage};
+ td class => 'tc2', $l->{minage} < 0 ? '' : minage $l->{minage};
td class => 'tc3';
$_ ne 'oth' && cssicon $_, mt "_plat_$_" for (@{$l->{platforms}});
cssicon "lang $_", mt "_lang_$_" for (@{$l->{languages}});
@@ -575,13 +573,13 @@ sub _fil_compat {
{ name => 'fw', required => 0, default => 0, enum => [ 0..2 ] },
{ name => 'do', required => 0, default => 0, enum => [ 0..2 ] },
{ name => 'ma_m', required => 0, default => 0, enum => [ 0, 1 ] },
- { name => 'ma_a', required => 0, default => 0, enum => [ grep defined($_), @{$self->{age_ratings}} ] },
+ { name => 'ma_a', required => 0, default => 0, enum => $self->{age_ratings} },
{ name => 'mi', required => 0, default => 0, template => 'int' },
{ name => 'ma', required => 0, default => 99999999, template => 'int' },
{ name => 're', required => 0, multi => 1, default => 0, enum => [ 1..$#{$self->{resolutions}} ] },
);
return if $f->{_err};
- $fil->{minage} //= [ grep defined($_) && $f->{ma_m} ? $f->{ma_a} >= $_ : defined ($_) && $f->{ma_a} <= $_, @{$self->{age_ratings}} ] if $f->{ma_a} || $f->{ma_m};
+ $fil->{minage} //= [ grep $_ >= 0 && ($f->{ma_m} ? $f->{ma_a} >= $_ : $f->{ma_a} <= $_), @{$self->{age_ratings}} ] if $f->{ma_a} || $f->{ma_m};
$fil->{date_after} //= $f->{mi} if $f->{mi};
$fil->{date_before} //= $f->{ma} if $f->{ma} < 99990000;
$fil->{plat} //= $f->{pl} if $f->{pl}[0];
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 1a3eb514..5747acba 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -406,7 +406,7 @@ sub _releases {
for my $rel (grep grep($_ eq $l, @{$_->{languages}}), @$r) {
Tr;
td class => 'tc1'; lit $self->{l10n}->datestr($rel->{released}); end;
- td class => 'tc2', !defined($rel->{minage}) ? '' : minage $rel->{minage};
+ td class => 'tc2', $rel->{minage} < 0 ? '' : minage $rel->{minage};
td class => 'tc3';
for (sort @{$rel->{platforms}}) {
next if $_ eq 'oth';