1 | package Vote::Controller::Vote; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Vote::Controller::Vote - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub begin : Private { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | $c->model('Vote')->rollback; |
---|
27 | } |
---|
28 | |
---|
29 | sub index : Private { |
---|
30 | my ( $self, $c ) = @_; |
---|
31 | |
---|
32 | $c->stash->{template} = 'default.tt'; |
---|
33 | $c->res->redirect($c->uri_for('/')); |
---|
34 | } |
---|
35 | |
---|
36 | sub default : LocalPath { |
---|
37 | my ( $self, $c, undef, $id ) = @_; |
---|
38 | |
---|
39 | $c->stash->{voteid} = $id; |
---|
40 | $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id)->info('label'); |
---|
41 | } |
---|
42 | |
---|
43 | sub report: LocalRegex('^(\d+)/report.(\w+)$') { |
---|
44 | my ($self, $c, $id, @sub) = @_; |
---|
45 | ($c->stash->{voteid}, $c->stash->{format}) = @{ $c->req->snippets || [] }; |
---|
46 | my $vote = $c->model('Vote'); |
---|
47 | $c->stash->{template} = 'default.tt'; |
---|
48 | |
---|
49 | $vote->poll($c->stash->{voteid})->info or do { |
---|
50 | $c->res->redirect($c->uri_for('/')); |
---|
51 | return; |
---|
52 | }; |
---|
53 | # Ensure report is not availlable before end of poll |
---|
54 | if ($vote->poll($c->stash->{voteid})->status ne 'AFTER') { |
---|
55 | $c->res->redirect($c->uri_for('/vote', $c->stash->{voteid})); |
---|
56 | return; |
---|
57 | }; |
---|
58 | |
---|
59 | |
---|
60 | $c->stash->{template} = 'poll_report.tt'; |
---|
61 | $c->stash->{latex} = 1; |
---|
62 | } |
---|
63 | |
---|
64 | sub end : Private { |
---|
65 | my ($self, $c) = @_; |
---|
66 | if ($c->res->body) { return } |
---|
67 | elsif ($c->stash->{latex}) { $c->forward(qw/Vote::View::Latex/) } |
---|
68 | else { $c->forward(qw/Vote::View::TT/) } |
---|
69 | } |
---|
70 | |
---|
71 | =head1 AUTHOR |
---|
72 | |
---|
73 | Thauvin Olivier |
---|
74 | |
---|
75 | =head1 LICENSE |
---|
76 | |
---|
77 | This library is free software, you can redistribute it and/or modify |
---|
78 | it under the same terms as Perl itself or CeCILL. |
---|
79 | |
---|
80 | =cut |
---|
81 | |
---|
82 | 1; |
---|