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

Last change on this file since 218 was 218, checked in by nanardon, 15 years ago
  • improve poll results view
File size: 1.7 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+)/(results|report).(\w+)$') {
44    my ($self, $c, $id, @sub) = @_;
45    my $doc;
46    ($c->stash->{voteid}, $doc, $c->stash->{format}) = @{ $c->req->snippets || [] };
47    my $vote = $c->model('Vote');
48    $c->stash->{template} = 'default.tt';
49
50    $vote->poll($c->stash->{voteid})->info or do {
51        $c->res->redirect($c->uri_for('/'));
52        return;
53    };
54    # Ensure report is not availlable before end of poll
55    if ($vote->poll($c->stash->{voteid})->status ne 'AFTER') {
56        $c->res->redirect($c->uri_for('/vote', $c->stash->{voteid}));
57        return;
58    };
59
60
61    $c->stash->{template} = "poll_$doc.tt";
62    $c->stash->{latex} = 1;
63}
64
65sub end : Private {
66    my ($self, $c) = @_;
67    if ($c->res->body) { return }
68    elsif ($c->stash->{latex}) { $c->forward(qw/Vote::View::Latex/) }
69    else { $c->forward(qw/Vote::View::TT/) }
70}
71
72=head1 AUTHOR
73
74Thauvin Olivier
75
76=head1 LICENSE
77
78This library is free software, you can redistribute it and/or modify
79it under the same terms as Perl itself or CeCILL.
80
81=cut
82
831;
Note: See TracBrowser for help on using the repository browser.