]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/Ct.pm
Add user list and user pages
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct.pm
CommitLineData
fe78f0c1
MG
1package Gruntmaster::Page::Ct;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
fe78f0c1 10use HTML::Template::Compiled;
fe78f0c1 11use POSIX qw/strftime/;
2b0036ac 12use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
4aa8ba86 13use Gruntmaster::Data qw/contests contest_name contest_start contest_end contest_owner/;
fe78f0c1 14
2b0036ac 15my %orig_templates = (
cd9af27e
MG
16 en => <<'HTML',
17<tmpl_if running>
fe78f0c1
MG
18<h1>Running contests</h1>
19<table border>
20<thead>
21<tr><th>Name<th>Start date<th>End date<th>Owner
22<tbody>
23<tmpl_loop running><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
24<td><tmpl_var start>
25<td><tmpl_var end>
26<td><tmpl_var owner>
27</tmpl_loop>
28</table>
29</tmpl_if>
30
cd9af27e 31<tmpl_if pending>
fe78f0c1
MG
32<h1>Pending contests</h1>
33<table border>
34<thead>
35<tr><th>Name<th>Start date<th>End date<th>Owner
36<tbody>
37<tmpl_loop pending><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
38<td><tmpl_var start>
39<td><tmpl_var end>
40<td><tmpl_var owner>
41</tmpl_loop>
42</table>
43</tmpl_if>
44
cd9af27e 45<tmpl_if finished>
fe78f0c1
MG
46<h1>Finished contests</h1>
47<table border>
48<thead>
49<tr><th>Name<th>Start date<th>End date<th>Owner
50<tbody>
51<tmpl_loop finished><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
52<td><tmpl_var start>
53<td><tmpl_var end>
54<td><tmpl_var owner>
55</tmpl_loop>
56</table>
57</tmpl_if>
58HTML
59);
60
2b0036ac 61my %templates = cook_templates %orig_templates, ct => 'Contests';
fe78f0c1
MG
62
63sub generate{
4aa8ba86 64 %templates = cook_templates %orig_templates, ct => 'Contests' if reload_templates;
cd9af27e 65 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
fe78f0c1 66
cd9af27e
MG
67 my (@running, @pending, @finished);
68 for (contests) {
69 my $ct = { id => $_,
70 name => contest_name,
71 start => strftime ('%c', localtime contest_start),
72 end => strftime ('%c', localtime contest_end),
73 owner => contest_owner };
fe78f0c1 74
cd9af27e
MG
75 my $time = time;
76 push @pending, $ct if time < contest_start;
77 push @running, $ct if time >= contest_start && time < contest_end;
78 push @finished, $ct if time > contest_end;
79 }
fe78f0c1 80
cd9af27e
MG
81 $htc->param(running => \@running);
82 $htc->param(pending => \@pending);
83 $htc->param(finished => \@finished);
84 $htc->output
fe78f0c1
MG
85}
86
871
This page took 0.028254 seconds and 4 git commands to generate.