diff options
author | Yorhel <git@yorhel.nl> | 2011-02-05 18:33:55 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-02-05 18:33:55 +0100 |
commit | bccc7326a43020e44aea345b803adaceaa90f2a2 (patch) | |
tree | 2efd0a89131865c616960f76771429893145c3d5 /lib | |
parent | 99b0bb54556d4300676056e8afe606d859e6417b (diff) |
Group tags on /v+/tagmod by their category
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 4 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 63 |
2 files changed, 41 insertions, 26 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm index a4451f98..8ed4cec6 100644 --- a/lib/VNDB/DB/Tags.pm +++ b/lib/VNDB/DB/Tags.pm @@ -249,13 +249,13 @@ sub dbTagStats { }->{ $o{sort}||'name' }, $o{reverse} ? 'DESC' : 'ASC'; my($r, $np) = $self->dbPage(\%o, qq| - SELECT t.id, t.name, count(*) as cnt, $rating as rating, + SELECT t.id, t.name, t.cat, 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 = ? - GROUP BY t.id, t.name + GROUP BY t.id, t.name, t.cat !s ORDER BY !s|, $o{vid}, defined $o{minrating} ? "HAVING $rating > $o{minrating}" : '', $order diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index c7d98060..974754c9 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -616,30 +616,7 @@ sub vntagmod { end; end; end 'tfoot'; tbody id => 'tagtable'; - for my $t (sort { $a->{name} cmp $b->{name} } @$tags) { - my $m = (grep $_->{tag} == $t->{id}, @$my)[0] || {}; - Tr id => "tgl_$t->{id}"; - td class => 'tc_tagname'; a href => "/g$t->{id}", $t->{name}; end; - td class => 'tc_myvote', $m->{vote}||0; - if($self->authCan('tagmod')) { - td class => 'tc_myover'; - input type => 'checkbox', name => 'overrule', value => $t->{id}, - $m->{vote} && !$m->{ignore} && $t->{overruled} ? (checked => 'checked') : () - if $t->{cnt} > 1; - end; - } - td class => 'tc_myspoil', defined $m->{spoiler} ? $m->{spoiler} : -1; - td class => 'tc_allvote'; - tagscore $t->{rating}; - i $t->{overruled} ? (class => 'grayedout') : (), " ($t->{cnt})"; - b class => 'standout', style => 'font-weight: bold', ' !' if $t->{overruled}; - end; - td class => 'tc_allspoil', sprintf '%.2f', $t->{spoiler}; - td class => 'tc_allwho'; - a href => "/g/links?v=$vid;t=$t->{id}", mt '_tagv_who'; - end; - end; - } + _tagmod_list($self, $vid, $tags, $my); end 'tbody'; end 'table'; } ], @@ -647,6 +624,44 @@ sub vntagmod { $self->htmlFooter; } +sub _tagmod_list { + my($self, $vid, $tags, $my) = @_; + + my %my = map +($_->{tag} => $_), @$my; + + for my $cat (@{$self->{tag_categories}}) { + my @tags = grep $_->{cat} eq $cat, @$tags; + next if !@tags; + Tr class => 'tagmod_cat'; + td colspan => 7, mt "_tagcat_$cat"; + end; + for my $t (@tags) { + my $m = $my{$t->{id}}; + Tr id => "tgl_$t->{id}"; + td class => 'tc_tagname'; a href => "/g$t->{id}", $t->{name}; end; + td class => 'tc_myvote', $m->{vote}||0; + if($self->authCan('tagmod')) { + td class => 'tc_myover'; + input type => 'checkbox', name => 'overrule', value => $t->{id}, + $m->{vote} && !$m->{ignore} && $t->{overruled} ? (checked => 'checked') : () + if $t->{cnt} > 1; + end; + } + td class => 'tc_myspoil', defined $m->{spoiler} ? $m->{spoiler} : -1; + td class => 'tc_allvote'; + tagscore $t->{rating}; + i $t->{overruled} ? (class => 'grayedout') : (), " ($t->{cnt})"; + b class => 'standout', style => 'font-weight: bold', ' !' if $t->{overruled}; + end; + td class => 'tc_allspoil', sprintf '%.2f', $t->{spoiler}; + td class => 'tc_allwho'; + a href => "/g/links?v=$vid;t=$t->{id}", mt '_tagv_who'; + end; + end; + } + } +} + sub tagindex { my $self = shift; |