Changeset 15
- Timestamp:
- 03/07/09 16:30:29 (15 years ago)
- Location:
- trunk
- Files:
-
- 9 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Model/Vote.pm
r14 r15 4 4 use warnings; 5 5 use base 'Catalyst::Model'; 6 use Vote; 6 7 use DBI; 7 8 … … 36 37 sub db { $_[0]->{db} } 37 38 38 sub list_ running_vote {39 sub list_comming_vote { 39 40 my ($self) = @_; 40 41 41 42 my $sth = $self->db->prepare_cached( 42 43 q{ 43 select id from poll where start < now() and "end" > now() 44 select id from poll where 45 (start > now() and "end" > now()) or 46 "end" is null or start is null 44 47 } 45 48 ); … … 54 57 } 55 58 59 60 sub list_running_vote { 61 my ($self) = @_; 62 63 my $sth = $self->db->prepare_cached( 64 q{ 65 select id from poll where start < now() and "end" > now() 66 } 67 ); 68 69 $sth->execute; 70 my @id; 71 while(my $res = $sth->fetchrow_hashref) { 72 push(@id, $res->{id}); 73 } 74 75 @id 76 } 77 78 sub list_closed_vote { 79 my ($self) = @_; 80 81 my $sth = $self->db->prepare_cached( 82 q{ 83 select id from poll where 84 start < now() and "end" < now() 85 } 86 ); 87 88 $sth->execute; 89 my @id; 90 while(my $res = $sth->fetchrow_hashref) { 91 push(@id, $res->{id}); 92 } 93 94 @id 95 } 96 56 97 sub vote_status { 57 98 my ($self, $id) = @_; … … 59 100 my $sth = $self->db->prepare_cached( 60 101 q{ 61 select start < now() as before 62 "end" > now() as after 102 select start > now() as before, 103 "end" < now() as after 104 from poll 63 105 where id = ? 64 106 } … … 110 152 } 111 153 154 sub vote_signing_count { 155 my ($self, $id) = @_; 156 157 my $sth = $self->db->prepare_cached( 158 q{ 159 select count(*) from voting 160 where poll = ? 161 } 162 ); 163 $sth->execute($id); 164 my $res = $sth->fetchrow_hashref; 165 $sth->finish; 166 $res->{count} 167 } 168 112 169 sub vote_choices { 113 170 my ($self, $id) = @_; … … 238 295 } 239 296 297 sub ballot_count_nonull { 298 my ($self, $voteid) = @_; 299 300 my $sth = $self->db->prepare_cached( 301 q{ 302 select count(*) from ballot where poll = ? 303 and id in (select id from ballot_item) 304 } 305 ); 306 307 $sth->execute($voteid); 308 my $res = $sth->fetchrow_hashref; 309 $sth->finish; 310 warn $res->{count}; 311 $res->{count} 312 } 313 240 314 sub auth_voting { 241 315 my ($self, $poll, $user, $password) = @_; … … 269 343 # Requete de decompte des voix: 270 344 271 # select count(ballot.id), value from ballot left join ballot_item 272 # on ballot.id = ballot_item.id where ballot.poll = 1 and invalid = 'false' 273 # group by value 274 # order by count 345 sub vote_results_count { 346 my ($self, $voteid) = @_; 347 348 my $sth = $self->db->prepare( 349 q{ 350 select count(ballot.id), value from ballot left join ballot_item 351 on ballot.id = ballot_item.id where ballot.poll = ? and invalid = 'false' 352 group by value 353 order by count 354 } 355 ); 356 $sth->execute($voteid); 357 my @results; 358 while (my $res = $sth->fetchrow_hashref) { 359 push(@results, $res); 360 } 361 @results; 362 } 363 364 sub vote_results_nonull { 365 my ($self, $voteid) = @_; 366 367 my $sth = $self->db->prepare( 368 q{ 369 select count(ballot.id), value from ballot join ballot_item 370 on ballot.id = ballot_item.id where ballot.poll = ? and invalid = 'false' 371 group by value 372 order by count desc 373 } 374 ); 375 $sth->execute($voteid); 376 my @results; 377 while (my $res = $sth->fetchrow_hashref) { 378 push(@results, $res); 379 } 380 \@results; 381 } 275 382 276 383 =head1 AUTHOR -
trunk/root/templates/ballot/default.tt
r12 r15 1 1 [% vote = c.model('Vote') %] 2 2 3 [% thisvote = vote.vote_info(voteid) %] 4 [% thisvote.label | html %] 5 [% signing = [vote.vote_signing(voteid)] %] 6 Ont voté: [% vote.signing_count(voteid) %] / [% signing.size %]<br> 7 Bulletins: [% vote.ballot_count(voteid) %]<br> 8 <hr> 3 [% INLCUDE 'includes/poll.tt' %] 9 4 10 5 [% IF c.req.param('ballot') %] -
trunk/root/templates/default.tt
r3 r15 2 2 [% vote = c.model('Vote') %] 3 3 4 <p>Vote en cours</p> 5 4 6 [% FOREACH id = vote.list_running_vote %] 7 <p><a href="[% c.uri_for( 'vote', id ) %]">[% vote.vote_info(id).label | html %]</a> 8 <a href="[% c.uri_for( 'ballot', id ) %]">Voter</a></p> 9 [% END %] 10 11 <p>Vote à venir</p> 12 13 [% FOREACH id = vote.list_comming_vote %] 5 14 <p><a href="[% c.uri_for( 'vote', id ) %]">[% vote.vote_info(id).label | html %]</a></p> 6 15 [% END %] 16 17 <p>Vote Fermé</p> 18 19 [% FOREACH id = vote.list_closed_vote %] 20 <p><a href="[% c.uri_for( 'vote', id ) %]">[% vote.vote_info(id).label | html %]</a></p> 21 [% END %] -
trunk/root/templates/vote/default.tt
r12 r15 1 1 [% vote = c.model('Vote') %] 2 2 3 [% thisvote = vote.vote_info(voteid) %] 4 [% thisvote.label | html %]<br> 3 [% INCLUDE 'includes/poll.tt' %] 4 5 [% SWITCH vote.vote_status(voteid) %] 6 [% CASE 'RUNNING' %] 7 <p>en cours</p> 8 [% CASE 'BEFORE' %] 9 <p>Avant</p> 10 [% CASE 'AFTER' %] 11 <p>Resultats:</p> 12 Nombre de bulletin exprimés: [% vote.ballot_count_nonull(voteid) %] 13 ([% vote.ballot_count_nonull(voteid) * 100 / vote.ballot_count(voteid) %]%) 14 <br> 15 16 <table border="1"> 17 <tr><th>choix</th><th>Nb voix</th><th>%</th><th></th></tr> 18 [% FOREACH res = vote.vote_results_nonull(voteid) %] 19 <tr> 20 <td>[% res.value | html %]</td> 21 <td>[% res.count %]</td> 22 <td>[% res.count * 100 / vote.ballot_count(voteid) %]</td> 23 <td><img src="[% c.uri_for('/static', 'images', 'green-h.png') %]" 24 height="10px" width="[% res.count * 300 / vote.ballot_count(voteid) %]px"></td> 25 </tr> 26 [% END %] 27 </table> 28 [% END %] 29 5 30 [% signing = [ vote.vote_signing(voteid) ] %] 6 Ont voté: [% vote.signing_count(voteid) %] / [% signing.size %]<br>7 Bulletins: [% vote.ballot_count(voteid) %]<br>8 9 31 [% FOREACH voting = signing %] 10 32 [% voting.id | html %] [% voting.date %]<br>
Note: See TracChangeset
for help on using the changeset viewer.