Changeset 15 for trunk/lib/Vote/Model/Vote.pm
- Timestamp:
- 03/07/09 16:30:29 (15 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.