]>
Commit | Line | Data |
---|---|---|
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 HTML::Template::Compiled; | |
11 | use POSIX qw/strftime/; | |
12 | use Gruntmaster::Page::Common qw/cook_templates reload_templates/; | |
13 | use Gruntmaster::Data qw/contests contest_name contest_start contest_end contest_owner/; | |
14 | ||
15 | my %orig_templates = ( | |
16 | en => <<'HTML', | |
17 | <tmpl_if running> | |
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 | ||
31 | <tmpl_if pending> | |
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 | ||
45 | <tmpl_if finished> | |
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> | |
58 | HTML | |
59 | ); | |
60 | ||
61 | my %templates = cook_templates %orig_templates, ct => 'Contests'; | |
62 | ||
63 | sub generate{ | |
64 | %templates = cook_templates %orig_templates, ct => 'Contests' if reload_templates; | |
65 | my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); | |
66 | ||
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 }; | |
74 | ||
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 | } | |
80 | ||
81 | $htc->param(running => \@running); | |
82 | $htc->param(pending => \@pending); | |
83 | $htc->param(finished => \@finished); | |
84 | $htc->output | |
85 | } | |
86 | ||
87 | 1 |