summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2018-10-27 12:35:40 +0200
committerYorhel <git@yorhel.nl>2018-10-27 12:35:42 +0200
commit29526b2b8342cf808864f84fc8672a9d0c486ae0 (patch)
treee3b4004a0f99c5cda6df3b81d0a75c631287a299 /lib/VNDB
parent95feae6a676d5d312b2ad9b2994d56842acb4795 (diff)
VNPage: Hide vote dropdown when nothing has been released yet
This is a lazy implementation - it doesn't fully prevent voting on unreleased VNs, but it makes it much harder to do so by accident. Fixes #5
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/Handler/VNPage.pm12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 6dfcdcd6..3502cb13 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -5,6 +5,8 @@ use strict;
use warnings;
use TUWF ':html', 'xml_escape';
use VNDB::Func;
+use List::Util 'min';
+use POSIX 'strftime';
TUWF::register(
@@ -435,7 +437,7 @@ sub page {
_producers($self, $r);
_relations($self, $v) if @{$v->{relations}};
_anime($self, $v) if @{$v->{anime}};
- _useroptions($self, $v) if $self->authInfo->{id};
+ _useroptions($self, $v, $r) if $self->authInfo->{id};
_affiliate_links($self, $r);
Tr class => 'nostripe';
@@ -682,7 +684,11 @@ sub _anime {
sub _useroptions {
- my($self, $v) = @_;
+ my($self, $v, $r) = @_;
+
+ # Voting option is hidden if nothing has been released yet
+ my $minreleased = min grep $_, map $_->{released}, @$r;
+ my $canvote = $minreleased && $minreleased < strftime '%Y%m%d', gmtime;
my $vote = $self->dbVoteGet(uid => $self->authInfo->{id}, vid => $v->{id})->[0];
my $list = $self->dbVNListGet(uid => $self->authInfo->{id}, vid => $v->{id})->[0];
@@ -691,7 +697,7 @@ sub _useroptions {
Tr;
td 'User options';
td;
- if($vote || !$wish) {
+ if($vote || ($canvote && !$wish)) {
Select id => 'votesel', name => $self->authGetCode("/v$v->{id}/vote");
option value => -3, $vote ? 'your vote: '.fmtvote($vote->{vote}) : 'not voted yet';
optgroup label => $vote ? 'Change vote' : 'Vote';