X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FCt.pm;h=a21bf77809d352a78ef06c358833c3467945cda9;hb=b7bd0bad53df03baf5dc302ade58bea4f73d0880;hp=c222e62217b05a2d8a16f3617b1c00a76ea252ad;hpb=fe78f0c128c35e68e65850b02057997bad6717fe;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/Ct.pm b/lib/Gruntmaster/Page/Ct.pm index c222e62..a21bf77 100644 --- a/lib/Gruntmaster/Page/Ct.pm +++ b/lib/Gruntmaster/Page/Ct.pm @@ -3,97 +3,31 @@ package Gruntmaster::Page::Ct; use 5.014000; use strict; use warnings; -use parent qw/Exporter/; -our @EXPORT_OK = qw/generate/; +use Gruntmaster::Page::Base ct => 'Contests'; +our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TITLE => 'Contests'; - -use Fcntl qw/:flock/; -use HTML::Template::Compiled; -use IO::File; -use POSIX qw/strftime/; -use YAML::Any qw/LoadFile/; -use Gruntmaster::Page qw/header footer/; - -my %templates = ( - en => <<'HTML', - -

Running contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
- - -

Pending contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
- - -

Finished contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
-HTML -); - -$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; -$templates{$_} .= footer $_ for keys %templates; - -sub generate{ - my $template = $templates{$_[1]}; - my $htc = HTML::Template::Compiled->new(scalarref => \$template); - IO::File->new('>ct/meta.yml')->close unless -f 'ct/meta.yml'; - flock my $metafh = IO::File->new(') { - my $meta = LoadFile $_; - my $id = (m,^ct/(.*)/meta.yml$,)[0]; - my $ct = { id => $id, - name => $meta->{name}, - start => strftime ('%c', localtime $meta->{start}), - end => strftime ('%c', localtime $meta->{end}), - owner => $meta->{owner}}; - - my $time = time; - push @pending, $ct if time < $meta->{start}; - push @running, $ct if time >= $meta->{start} && time < $meta->{end}; - push @finished, $ct if time > $meta->{end}; - } - - $htc->param(runningn => scalar @running); - $htc->param(pendingn => scalar @pending); - $htc->param(finishedn => scalar @finished); - $htc->param(running => \@running); - $htc->param(pending => \@pending); - $htc->param(finished => \@finished); - $htc->output +sub _generate{ + my ($self, $htc, $lang, $env) = @_; + debug $env => "language is '$lang'"; + + my (@running, @pending, @finished); + for (sort {contest_start $a <=> contest_start $b}contests) { + my $ct = { id => $_, + name => contest_name, + start => strftime ('%c', localtime contest_start), + end => strftime ('%c', localtime contest_end), + owner => contest_owner }; + + my $time = time; + push @pending, $ct if time < contest_start; + push @running, $ct if time >= contest_start && time < contest_end; + push @finished, $ct if time > contest_end; + } + + $htc->param(running => \@running) if @running; + $htc->param(pending => \@pending) if @pending; + $htc->param(finished => \@finished) if @finished; } 1