Changeset 193


Ignore:
Timestamp:
04/14/09 18:19:40 (15 years ago)
Author:
nanardon
Message:
  • add new objects for poll results
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r183 r193  
    2525lib/Vote/DB/common.pm 
    2626lib/Vote/DB/Poll.pm 
     27lib/Vote/DB/Poll/Results.pm 
    2728lib/Vote/DB/Voting.pm 
    2829lib/Vote/DB/Ballot.pm 
  • trunk/lib/Vote/DB.pm

    r182 r193  
    88use base 'Vote::DB::common'; 
    99use Vote::DB::Poll; 
     10use Vote::DB::Poll::Results; 
    1011use Vote::DB::Ballot; # see ballot() 
    1112use Vote::DB::Voting; # see delete_voting() 
     
    9394} 
    9495 
     96sub results { 
     97    my ($self, $pollid) = @_; 
     98    Vote::DB::Poll::Results->new($self->{dbstring}, $pollid); 
     99} 
     100 
    95101sub ballot { 
    96102    my ($self, $ballotid) = @_; 
     
    194200sub vote_ballot_count_nonull { 
    195201    my ($self, $voteid) = @_; 
    196     $self->poll($voteid)->ballot_count_nonull; 
     202    $self->results($voteid)->ballot_count_nonull; 
    197203} 
    198204 
     
    217223sub vote_results_count { 
    218224    my ($self, $voteid) = @_; 
    219     $self->poll($voteid)->results_count; 
     225    $self->results($voteid)->results_count; 
    220226} 
    221227 
    222228sub vote_results_nonull { 
    223229    my ($self, $voteid) = @_; 
    224     $self->poll($voteid)->results_nonull; 
     230    $self->results($voteid)->results_nonull; 
    225231} 
    226232 
  • trunk/lib/Vote/DB/Poll.pm

    r191 r193  
    527527} 
    528528 
    529 sub ballot_count_nonull { 
    530     my ($self) = @_; 
    531  
    532     my $sth = $self->db->prepare_cached( 
    533         q{ 
    534         select count(*) from ballot where poll = ? 
    535         and id in (select id from ballot_item) and 
    536         (invalid = 'false' or invalid is null) 
    537         } 
    538     ); 
    539  
    540     $sth->execute($self->voteid); 
    541     my $res = $sth->fetchrow_hashref; 
    542     $sth->finish; 
    543     $res->{count} 
    544 } 
    545  
    546529sub voting_info_id { 
    547530    my ($self, $mail) = @_; 
     
    601584 
    602585    return 1; 
    603 } 
    604  
    605 sub results_count { 
    606     my ($self) = @_; 
    607  
    608     my $sth = $self->db->prepare( 
    609         q{ 
    610         select count(ballot.id), value from  
    611         (select ballot.id, coalesce(corrected, value) as "value" from ballot left join ballot_item 
    612         on ballot.id = ballot_item.id where ballot.poll = ? and (invalid = 'false'or invalid is null) 
    613         group by ballot.id, coalesce(corrected, value)) as ballot 
    614         group by value 
    615         order by count desc, value 
    616         } 
    617     ); 
    618     $sth->execute($self->voteid); 
    619     my @results; 
    620     while (my $res = $sth->fetchrow_hashref) { 
    621         push(@results, $res); 
    622     } 
    623     @results; 
    624 } 
    625  
    626 sub results_nonull { 
    627     my ($self) = @_; 
    628  
    629     my $sth = $self->db->prepare( 
    630         q{ 
    631         select count(ballot.id), value from  
    632         (select ballot.id, coalesce(corrected, value) as "value" from ballot join ballot_item 
    633         on ballot.id = ballot_item.id where ballot.poll = ? and (invalid = 'false'or invalid is null) 
    634         group by ballot.id, coalesce(corrected, value)) as ballot 
    635         group by value 
    636         order by count desc, value 
    637         } 
    638     ); 
    639     $sth->execute($self->voteid); 
    640     my @results; 
    641     while (my $res = $sth->fetchrow_hashref) { 
    642         push(@results, $res); 
    643     } 
    644     \@results; 
    645586} 
    646587 
  • trunk/root/latex/poll_report.tt

    r188 r193  
    11[% USE Mail %] 
    2 [%- poll = c.model('Vote').poll(voteid) %] 
     2[%- poll = c.model('Vote').results(voteid) %] 
    33 
    44\maketitle 
     
    5454 
    5555[%- IF loop.count <= poll.info.choice_count -%] 
    56 [%- IF res.count >= poll.ballot_count_nonull / 2 + 1 -%] 
     56[%- IF res.count >= poll.absolute_majority -%] 
    5757[%- comment = 'majorité absolue' -%] 
    5858[%- ELSE -%] 
  • trunk/root/templates/includes/poll_results.tt

    r183 r193  
    4343[% mycount = loop.count %] 
    4444[% IF loop.count <= vote.vote_info(voteid).choice_count %] 
    45 [% IF res.count >= vote.ballot_count_nonull(voteid) / 2 + 1 %] 
     45[% IF res.count >= vote.absolute_majority %] 
    4646[% class = 'majabs' %] 
    4747[% ELSE %] 
Note: See TracChangeset for help on using the changeset viewer.