Changeset 218 for trunk/lib


Ignore:
Timestamp:
04/18/09 17:20:17 (15 years ago)
Author:
nanardon
Message:
  • improve poll results view
Location:
trunk/lib/Vote
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Controller/Vote.pm

    r207 r218  
    4141} 
    4242 
    43 sub report: LocalRegex('^(\d+)/report.(\w+)$') { 
     43sub report: LocalRegex('^(\d+)/(results|report).(\w+)$') { 
    4444    my ($self, $c, $id, @sub) = @_; 
    45     ($c->stash->{voteid}, $c->stash->{format}) = @{ $c->req->snippets || [] }; 
     45    my $doc; 
     46    ($c->stash->{voteid}, $doc, $c->stash->{format}) = @{ $c->req->snippets || [] }; 
    4647    my $vote = $c->model('Vote'); 
    4748    $c->stash->{template} = 'default.tt'; 
     
    5859 
    5960 
    60     $c->stash->{template} = 'poll_report.tt'; 
     61    $c->stash->{template} = "poll_$doc.tt"; 
    6162    $c->stash->{latex} = 1; 
    6263} 
  • trunk/lib/Vote/DB/Poll/Results.pm

    r217 r218  
    5252sub voices_ballot_count { 
    5353    my ($self) = @_; 
    54     return $self->not_empty_ballot_count + 
    55         ($self->info('empty_ballot_has_voice') 
    56             ? $self->empty_ballot_count 
    57             : 0); 
    58 } 
    59  
     54    return $self->info('empty_ballot_has_voice') 
     55            ? $self->valid_ballot_count 
     56            : $self->not_empty_ballot_count; 
     57} 
     58 
     59sub valid_ballot_count { 
     60    my ($self) = @_; 
     61 
     62    my $sth = $self->db->prepare_cached( 
     63        q{ 
     64        select count(*) from ballot where poll = ? 
     65        and (invalid = 'f' or invalid is NULL) 
     66        } 
     67    ); 
     68 
     69    $sth->execute($self->voteid); 
     70    my $res = $sth->fetchrow_hashref; 
     71    $sth->finish; 
     72    $res->{count} 
     73} 
     74 
     75sub invalid_ballot_count { 
     76    my ($self) = @_; 
     77 
     78    my $sth = $self->db->prepare_cached( 
     79        q{ 
     80        select count(*) from ballot where poll = ? 
     81        and invalid = 't' 
     82        } 
     83    ); 
     84 
     85    $sth->execute($self->voteid); 
     86    my $res = $sth->fetchrow_hashref; 
     87    $sth->finish; 
     88    $res->{count} 
     89} 
    6090 
    6191sub empty_ballot_count { 
     
    6595        q{ 
    6696        select count(*) from ballot where poll = ? 
    67         and id not in (select id from ballot_item) and 
    68         (invalid = 'false' or invalid is null) 
     97        and id not in (select id from ballot_item) 
     98        and (invalid = 'false' or invalid is null) 
    6999        } 
    70100    ); 
     
    82112        q{ 
    83113        select count(*) from ballot where poll = ? 
    84         and id in (select id from ballot_item) and 
    85         (invalid = 'false' or invalid is null) 
     114        and id in (select id from ballot_item) 
     115        and (invalid = 'false' or invalid is null) 
    86116        } 
    87117    ); 
Note: See TracChangeset for help on using the changeset viewer.