source: trunk/lib/Vote/Controller/Vote.pm @ 207

Last change on this file since 207 was 207, checked in by nanardon, 15 years ago
  • cleanup old functions and switch everything to new objects
File size: 1.6 KB
Line 
1package Vote::Controller::Vote;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7=head1 NAME
8
9Vote::Controller::Vote - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub begin : Private {
25    my ( $self, $c ) = @_;
26    $c->model('Vote')->rollback;
27}
28
29sub index : Private {
30    my ( $self, $c ) = @_;
31
32    $c->stash->{template} = 'default.tt';
33    $c->res->redirect($c->uri_for('/'));
34}
35
36sub 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
43sub 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
64sub 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
73Thauvin Olivier
74
75=head1 LICENSE
76
77This library is free software, you can redistribute it and/or modify
78it under the same terms as Perl itself or CeCILL.
79
80=cut
81
821;
Note: See TracBrowser for help on using the repository browser.