summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Tags.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-02-22 12:32:57 +0100
committerYorhel <git@yorhel.nl>2009-02-22 12:32:57 +0100
commit8e8bf25368ce0e8371e3aa45ce75c560819ed92b (patch)
tree815bd858bd7288d4c56a658b541e97c9f7784e8a /lib/VNDB/DB/Tags.pm
parentc8e759f0ea8b54a21822481458ddb00a3373bc08 (diff)
Very basic, unfinished and non-working interface for VN/tag linking
But it already starts to look like something that might work.
Diffstat (limited to 'lib/VNDB/DB/Tags.pm')
-rw-r--r--lib/VNDB/DB/Tags.pm28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 7327daf2..f7151431 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|;
+our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbVNTags|;
# %options->{ id name page results order what }
@@ -85,5 +85,31 @@ sub dbTagDel {
}
+# Directly fetch rows from tags_vn
+# Arguments: %options->{ vid uid tag }
+sub dbTagLinks {
+ my($self, %o) = @_;
+ return $self->dbAll(
+ 'SELECT tag, vid, uid, vote, spoiler FROM tags_vn !W',
+ { map { +"$_ = ?" => $o{$_} } keys %o }
+ );
+}
+
+
+# Fetch all tags related to a VN
+# Argument: vid
+sub dbVNTags {
+ my($self, $vid) = @_;
+ return $self->dbAll(q|
+ SELECT t.id, t.name, count(tv.uid) as users, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler
+ FROM tags t
+ JOIN tags_vn tv ON tv.tag = t.id
+ WHERE tv.vid = ?
+ GROUP BY t.id, t.name|,
+ $vid
+ );
+}
+
+
1;