summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-01-03 21:37:30 +0100
committerYorhel <git@yorhel.nl>2011-01-03 21:39:22 +0100
commita48a7f5b0d4e65a70337d40f7df287810f27d547 (patch)
tree7c922bccf1aa2c4e36a6fc5e8f0d466c2ce61605 /lib
parentdf6dc445df2f73381829b8af8db606cea67f589d (diff)
Added tag overrule indicators to tag link browser and VN tag editor
This is the second step in adding support for overruling tag votes by moderators. This required a different approach to calculating the score in dbTagStats(). For some reason this approach turns out to be slightly faster as well...
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Tags.pm16
-rw-r--r--lib/VNDB/Handler/Tags.pm5
2 files changed, 12 insertions, 9 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 93705de0..623ac10d 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -176,7 +176,7 @@ sub dbTagLinks {
);
my @select = (
- qw|tv.tag tv.vid tv.uid tv.vote tv.spoiler|, "EXTRACT('epoch' from tv.date) AS date",
+ qw|tv.tag tv.vid tv.uid tv.vote tv.spoiler tv.ignore|, "EXTRACT('epoch' from tv.date) AS date",
$o{what} =~ /details/ ? (qw|vr.title u.username t.name|) : (),
);
@@ -243,25 +243,27 @@ sub dbTagStats {
$o{results} ||= 10;
$o{page} ||= 1;
+ my $rating = 'avg(CASE WHEN tv.ignore THEN NULL ELSE tv.vote END)';
my $order = sprintf {
name => 't.name %s',
- rating => 'avg(tv.vote) %s',
+ rating => "$rating %s",
}->{ $o{sort}||'name' }, $o{reverse} ? 'DESC' : 'ASC';
- my($r, $np) = $self->dbPage(\%o, q|
- SELECT t.id, t.name, count(*) as cnt, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler
+ my($r, $np) = $self->dbPage(\%o, qq|
+ SELECT t.id, t.name, count(*) as cnt, $rating as rating,
+ COALESCE(avg(CASE WHEN tv.ignore THEN NULL ELSE tv.spoiler END), 0) as spoiler,
+ bool_or(tv.ignore) AS overruled
FROM tags t
JOIN tags_vn tv ON tv.tag = t.id
- WHERE tv.vid = ? AND NOT tv.ignore
+ WHERE tv.vid = ?
GROUP BY t.id, t.name
!s
ORDER BY !s|,
- $o{vid}, defined $o{minrating} ? "HAVING avg(tv.vote) > $o{minrating}" : '', $order
+ $o{vid}, defined $o{minrating} ? "HAVING $rating > $o{minrating}" : '', $order
);
return wantarray ? ($r, $np) : $r;
}
-
1;
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index ad736027..7d9b10fa 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -450,7 +450,7 @@ sub taglinks {
a href => $url->(u=>$l->{uid}), class => 'setfil', '> ' if !$f->{u};
a href => "/u$l->{uid}", $l->{username};
end;
- td class => 'tc3';
+ td class => 'tc3'.($l->{ignore}?' ignored':'');
tagscore $l->{vote};
end;
td class => 'tc4';
@@ -544,7 +544,8 @@ sub vntagmod {
td class => 'tc_myspoil', defined $m->{spoiler} ? $m->{spoiler} : -1;
td class => 'tc_allvote';
tagscore !$m->{vote} ? $t->{rating} : $t->{cnt} == 1 ? 0 : ($t->{rating}*$t->{cnt} - $m->{vote}) / ($t->{cnt}-1);
- i ' ('.($t->{cnt} - ($m->{vote} ? 1 : 0)).')';
+ i $t->{overruled} ? (class => 'grayedout') : (), ' ('.($t->{cnt} - ($m->{vote} ? 1 : 0)).')';
+ b class => 'standout', style => 'font-weight: bold', ' !' if $t->{overruled};
end;
td class => 'tc_allspoil', sprintf '%.2f', $t->{spoiler};
td class => 'tc_allwho';