summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-03-07 00:01:34 +0100
committerYorhel <git@yorhel.nl>2009-03-07 00:01:34 +0100
commit0680666a8659e75a90d581f8f3a0e3172c16bcd1 (patch)
treed04490b676c1831962e9f3955f8202a3bdaecf6c
parenteaa8088edb36565d5dd232a624003f3aaef9ee9e (diff)
Adding list of VNs to tag pages
-rw-r--r--data/style.css5
-rw-r--r--lib/VNDB/DB/Tags.pm22
-rw-r--r--lib/VNDB/Handler/Tags.pm58
-rw-r--r--util/updates/update_2.3.sql2
4 files changed, 85 insertions, 2 deletions
diff --git a/data/style.css b/data/style.css
index 2b84a4c6..095f14b4 100644
--- a/data/style.css
+++ b/data/style.css
@@ -969,6 +969,11 @@ ul#catselect li li.exc { background-position: 0px -33px; color: $statnok$; }
.tagtree li { float: left; width: 200px; margin-top: 10px; }
.tagtree li li { float: none; width: auto; margin-top: 0; }
.tagtree ul { margin-left: 10px; list-style-type: none; }
+.tagvnlist .tc1 { text-align: right; width: 60px; }
+.tagvnlist .tc1 i { font-style: normal; font-size: 8px }
+.tagvnlist .tc3 { text-align: right; padding: 0; }
+.tagvnlist .tc4 { padding: 0; }
+.tagvnlist .tc6 { text-align: right; padding-right: 10px; }
/***** VN tagmod *****/
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 9ed6560b..e6607a2a 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbTagLinkEdit dbVNTags|;
+our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbTagLinkEdit dbVNTags dbTagVNs|;
# %options->{ id name search page results order what }
@@ -125,5 +125,25 @@ sub dbVNTags {
);
}
+
+# Fetch all VNs from a tag, including VNs from child tags, and provide ratings for them.
+# Argument: %options->{ tag order page results }
+sub dbTagVNs {
+ my($self, %o) = @_;
+ $o{order} ||= 'tb.rating DESC';
+ $o{page} ||= 1;
+ $o{results} ||= 10;
+
+ 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 = ?
+ ORDER BY !s|,
+ $o{tag}, $o{order});
+ return wantarray ? ($r, $np) : $r;
+}
+
1;
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 614123df..b0e698dc 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -26,6 +26,21 @@ sub tagpage {
my $t = $self->dbTagGet(id => $tag, what => 'parents(0) childs(2)')->[0];
return 404 if !$t;
+ my $f = $self->formValidate(
+ { 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
+ );
+ return 404 if $f->{_err};
+
+ my($list, $np) = $t->{meta} ? ([],0) : $self->dbTagVNs(
+ tag => $tag,
+ 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,
+ );
+
my $title = ($t->{meta} ? 'Meta tag: ' : 'Tag: ').$t->{name};
$self->htmlHeader(title => $title);
$self->htmlMainTabs('g', $t);
@@ -67,6 +82,49 @@ sub tagpage {
_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';
+ txt sprintf '%.2f ', $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;
+ }
+ );
+ }
+
$self->htmlFooter;
}
diff --git a/util/updates/update_2.3.sql b/util/updates/update_2.3.sql
index da43c8e1..533a6581 100644
--- a/util/updates/update_2.3.sql
+++ b/util/updates/update_2.3.sql
@@ -105,7 +105,7 @@ DECLARE
i RECORD;
l RECORD;
BEGIN
- FOR l IN SElECT id FROM tags WHERE EXISTS(SELECT 1 FROM tags_parents WHERE parent = id) LOOP
+ FOR l IN SElECT id FROM tags WHERE meta = FALSE AND EXISTS(SELECT 1 FROM tags_parents WHERE parent = id) LOOP
FOR i IN SELECT tag FROM tag_tree(l.id, 0, true) LOOP
FOR r IN SELECT l.id, vid, uid, vote, spoiler FROM tags_vn WHERE tag = i.tag LOOP
RETURN NEXT r;