summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VNDB/DB/Tags.pm12
-rw-r--r--lib/VNDB/Handler/Tags.pm103
-rw-r--r--util/updates/update_2.3.sql2
3 files changed, 69 insertions, 48 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index dfa9b6b3..3e06d1b8 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -130,21 +130,27 @@ sub dbVNTags {
# Fetch all VNs from a tag, including VNs from child tags, and provide ratings for them.
-# Argument: %options->{ tag order page results }
+# Argument: %options->{ tag order page results maxspoil }
sub dbTagVNs {
my($self, %o) = @_;
$o{order} ||= 'tb.rating DESC';
$o{page} ||= 1;
$o{results} ||= 10;
+ my %where = (
+ 'tag = ?' => $o{tag},
+ defined $o{maxspoil} ? (
+ 'tb.spoiler <= ?' => $o{maxspoil} ) : (),
+ );
+
my($r, $np) = $self->dbPage(\%o, q|
SELECT tb.tag, tb.vid, tb.users, tb.rating, tb.spoiler, vr.title, vr.original, v.c_languages, v.c_released, v.c_platforms, v.c_popularity
FROM tags_vn_bayesian tb
JOIN vn v ON v.id = tb.vid
JOIN vn_rev vr ON vr.id = v.latest
- WHERE tag = ?
+ !W
ORDER BY !s|,
- $o{tag}, $o{order});
+ \%where, $o{order});
return wantarray ? ($r, $np) : $r;
}
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 0d2e7410..55f8fe7a 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -30,7 +30,7 @@ sub tagpage {
{ name => 's', required => 0, default => 'score', enum => [ qw|score title rel pop| ] },
{ name => 'o', required => 0, default => 'd', enum => [ 'a','d' ] },
{ name => 'p', required => 0, default => 1, template => 'int' },
- # TODO: hiding spoilers
+ { name => 'm', required => 0, default => 1, enum => [qw|0 1 2|] },
);
return 404 if $f->{_err};
@@ -39,6 +39,7 @@ sub tagpage {
order => {score=>'tb.rating',title=>'vr.title',rel=>'v.c_released',pop=>'v.c_popularity'}->{$f->{s}}.($f->{o}eq'a'?' ASC':' DESC'),
page => $f->{p},
results => 50,
+ maxspoil => $f->{m},
);
my $title = ($t->{meta} ? 'Meta tag: ' : 'Tag: ').$t->{name};
@@ -81,49 +82,7 @@ sub tagpage {
end;
_childtags($self, $t) if @{$t->{childs}};
-
- if(@$list) {
- $self->htmlBrowse(
- class => 'tagvnlist',
- items => $list,
- options => $f,
- nextpage => $np,
- pageurl => "/g$tag?o=$f->{o};s=$f->{s}",
- sorturl => "/g$tag",
- header => [
- [ 'Score', 'score' ],
- [ 'Title', 'title' ],
- [ '', 0 ],
- [ '', 0 ],
- [ 'Released', 'rel' ],
- [ 'Popularity', 'pop' ],
- ],
- row => sub {
- my($s, $n, $l) = @_;
- Tr $n % 2 ? (class => 'odd') : ();
- td class => 'tc1';
- tagscore $l->{rating};
- i sprintf '(%d)', $l->{users};
- end;
- td class => 'tc2';
- a href => '/v'.$l->{vid}, title => $l->{original}||$l->{title}, shorten $l->{title}, 100;
- end;
- td class => 'tc3';
- $_ ne 'oth' && cssicon $_, $self->{platforms}{$_}
- for (sort split /\//, $l->{c_platforms});
- end;
- td class => 'tc4';
- cssicon "lang $_", $self->{languages}{$_}
- for (reverse sort split /\//, $l->{c_languages});
- end;
- td class => 'tc5';
- lit monthstr $l->{c_released};
- end;
- td class => 'tc6', sprintf '%.2f', $l->{c_popularity}*100;
- end;
- }
- );
- }
+ _vnlist($self, $t, $f, $list, $np) if !$t->{meta};
$self->htmlFooter;
}
@@ -174,6 +133,62 @@ sub _childtags {
end;
}
+sub _vnlist {
+ my($self, $t, $f, $list, $np) = @_;
+ div class => 'mainbox';
+ h1 'Visual novels';
+ p class => 'browseopts';
+ a href => "/g$t->{id}?m=0", $f->{m} == 0 ? (class => 'optselected') : (), 'Hide spoilers';
+ a href => "/g$t->{id}?m=1", $f->{m} == 1 ? (class => 'optselected') : (), 'Show minor spoilers';
+ a href => "/g$t->{id}?m=2", $f->{m} == 2 ? (class => 'optselected') : (), 'Show major spoilers';
+ end;
+ if(!@$list) {
+ p "\n\nThis tag has not been linked to any visual novels yet, or they were hidden because of the spoiler settings.";
+ }
+ end;
+ return if !@$list;
+ $self->htmlBrowse(
+ class => 'tagvnlist',
+ items => $list,
+ options => $f,
+ nextpage => $np,
+ pageurl => "/g$t->{id}?m=$f->{m};o=$f->{o};s=$f->{s}",
+ sorturl => "/g$t->{id}?m=$f->{m}",
+ header => [
+ [ 'Score', 'score' ],
+ [ 'Title', 'title' ],
+ [ '', 0 ],
+ [ '', 0 ],
+ [ 'Released', 'rel' ],
+ [ 'Popularity', 'pop' ],
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ td class => 'tc1';
+ tagscore $l->{rating};
+ i sprintf '(%d)', $l->{users};
+ end;
+ td class => 'tc2';
+ a href => '/v'.$l->{vid}, title => $l->{original}||$l->{title}, shorten $l->{title}, 100;
+ end;
+ td class => 'tc3';
+ $_ ne 'oth' && cssicon $_, $self->{platforms}{$_}
+ for (sort split /\//, $l->{c_platforms});
+ end;
+ td class => 'tc4';
+ cssicon "lang $_", $self->{languages}{$_}
+ for (reverse sort split /\//, $l->{c_languages});
+ end;
+ td class => 'tc5';
+ lit monthstr $l->{c_released};
+ end;
+ td class => 'tc6', sprintf '%.2f', $l->{c_popularity}*100;
+ end;
+ }
+ );
+}
+
sub tagedit {
my($self, $tag, $act) = @_;
diff --git a/util/updates/update_2.3.sql b/util/updates/update_2.3.sql
index 533a6581..02a32106 100644
--- a/util/updates/update_2.3.sql
+++ b/util/updates/update_2.3.sql
@@ -141,7 +141,7 @@ CREATE OR REPLACE VIEW tags_vn_bayesian AS
SELECT tag, vid, users,
( (SELECT AVG(users)::real * AVG(rating)::real FROM tags_vn_inherited WHERE tag = tvi.tag) + users*rating )
/ ( (SELECT AVG(users)::real FROM tags_vn_inherited WHERE tag = tvi.tag) + users )::real AS rating,
- spoiler -- <- some kind of bayesian average for the spoiler status? or is AVG() good enough?
+ (CASE WHEN spoiler < 0.7 THEN 0 WHEN spoiler > 1.3 THEN 2 ELSE 1 END)::smallint AS spoiler
FROM tags_vn_inherited tvi;