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