summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Tags.pm10
-rw-r--r--lib/VNDB/Handler/Tags.pm6
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 8c27e55f..fb4717d8 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -39,7 +39,7 @@ sub dbTagGet {
't.meta = ?' => $o{meta}?1:0 ) : (),
);
my @select = (
- qw|t.id t.meta t.name t.description t.state t.cat t.c_items|,
+ qw|t.id t.meta t.name t.description t.state t.cat t.c_items t.defaultspoil|,
q|extract('epoch' from t.added) as added|,
$o{what} =~ /addedby/ ? ('t.addedby', 'u.username') : (),
);
@@ -129,7 +129,7 @@ sub dbTagEdit {
$self->dbExec('UPDATE tags !H WHERE id = ?', {
$o{upddate} ? ('added = NOW()' => 1) : (),
- map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name meta description state cat|
+ map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name meta description state cat defaultspoil|
}, $id);
if($o{aliases}) {
$self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id);
@@ -147,8 +147,8 @@ sub dbTagEdit {
# returns the id of the new tag
sub dbTagAdd {
my($self, %o) = @_;
- my $id = $self->dbRow('INSERT INTO tags (name, meta, description, state, cat, addedby) VALUES (!l, ?) RETURNING id',
- [ map $o{$_}, qw|name meta description state cat| ], $o{addedby}||$self->authInfo->{id}
+ my $id = $self->dbRow('INSERT INTO tags (name, meta, description, state, cat, defaultspoil, addedby) VALUES (!l, ?) RETURNING id',
+ [ map $o{$_}, qw|name meta description state cat defaultspoil| ], $o{addedby}||$self->authInfo->{id}
)->{id};
$self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}});
$self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}});
@@ -257,7 +257,7 @@ sub dbTagStats {
my($r, $np) = $self->dbPage(\%o, qq|
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,
+ COALESCE(avg(CASE WHEN tv.ignore THEN NULL ELSE tv.spoiler END), t.defaultspoil) as spoiler,
bool_or(tv.ignore) AS overruled
FROM tags t
JOIN tags_vn tv ON tv.tag = t.id
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 141c75aa..6b02a6dd 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -162,6 +162,7 @@ sub tagedit {
{ post => 'meta', required => 0, default => 0 },
{ post => 'alias', required => 0, maxlength => 1024, default => '', regex => [ qr/^[^,]+$/s, 'No comma allowed in aliases' ] },
{ post => 'description', required => 0, maxlength => 10240, default => '' },
+ { post => 'defaultspoil',required => 0, default => 0, enum => [ 0..2 ] },
{ post => 'parents', required => !$self->authCan('tagmod'), default => '' },
{ post => 'merge', required => 0, default => '' },
);
@@ -187,6 +188,7 @@ sub tagedit {
cat => $frm->{cat},
description => $frm->{description},
meta => $frm->{meta}?1:0,
+ defaultspoil => $frm->{defaultspoil},
aliases => \@aliases,
parents => \@parents,
);
@@ -203,7 +205,7 @@ sub tagedit {
}
if($tag) {
- $frm->{$_} ||= $t->{$_} for (qw|name meta description state cat|);
+ $frm->{$_} ||= $t->{$_} for (qw|name meta description state cat defaultspoil|);
$frm->{alias} ||= join "\n", @{$t->{aliases}};
$frm->{parents} ||= join ', ', map $_->{name}, @{$t->{parents}};
}
@@ -249,6 +251,8 @@ sub tagedit {
[ textarea => short => 'alias', name => "Aliases\n(separated by newlines)", cols => 30, rows => 4 ],
[ textarea => short => 'description', name => 'Description' ],
[ static => content => 'What should the tag be used for? Having a good description helps users choose which tags to link to a VN.' ],
+ [ select => short => 'defaultspoil', name => 'Default spoiler level', options => [ map [$_, fmtspoil $_], 0..2 ] ],
+ [ static => content => 'This is the spoiler level that will be used by default when everyone has voted "neutral".' ],
[ input => short => 'parents', name => 'Parent tags' ],
[ static => content => 'Comma separated list of tag names to be used as parent for this tag.' ],
$self->authCan('tagmod') ? (