Ignore:
Timestamp:
04/17/09 15:32:47 (15 years ago)
Author:
nanardon
Message:
  • more results function, support empty ballots in voices count
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/DB/Poll.pm

    r213 r214  
    513513} 
    514514 
    515 sub voting_count { 
    516     my ($self) = @_; 
    517  
    518     my $sth = $self->db->prepare_cached( 
    519         q{ 
    520         select count(*) from voting 
    521         where poll = ? 
    522         } 
    523     ); 
    524     $sth->execute($self->voteid); 
    525     my $res = $sth->fetchrow_hashref; 
    526     $sth->finish; 
    527     $res->{count} 
    528 } 
    529  
    530 sub signing_count { 
    531     my ($self) = @_; 
    532  
    533     my $sth = $self->db->prepare_cached( 
    534         q{ 
    535         select count(*) from signing join voting 
    536         on voting.key = signing.key where poll = ? 
    537         } 
    538     ); 
    539  
    540     $sth->execute($self->voteid); 
    541     my $res = $sth->fetchrow_hashref; 
    542     $sth->finish; 
    543     $res->{count} 
    544 } 
    545  
    546515sub is_crypted { 
    547516    my ($self) = @_; 
    548517    return $self->info->{public_key} ? 1 : 0; 
    549 } 
    550  
    551 sub ballot_count { 
    552     my ($self) = @_; 
    553     return $self->is_crypted 
    554         ? $self->ballot_count_crypt 
    555         : $self->ballot_count_clear; 
    556 } 
    557  
    558 sub ballot_count_clear { 
    559     my ($self) = @_; 
    560  
    561     my $sth = $self->db->prepare_cached( 
    562         q{select count(*) from ballot where poll = ?} 
    563     ); 
    564  
    565     $sth->execute($self->voteid); 
    566     my $res = $sth->fetchrow_hashref; 
    567     $sth->finish; 
    568     $res->{count} 
    569 } 
    570  
    571 sub ballot_count_crypt { 
    572     my ($self) = @_; 
    573  
    574     my $sth = $self->db->prepare_cached( 
    575         q{select count(*) from ballot_enc where poll = ?} 
    576     ); 
    577  
    578     $sth->execute($self->voteid); 
    579     my $res = $sth->fetchrow_hashref; 
    580     $sth->finish; 
    581     $res->{count} 
    582518} 
    583519 
     
    890826    $privkey 
    891827} 
     828 
     829######### 
     830# Count # 
     831######### 
     832 
     833sub ballot_count { 
     834    my ($self) = @_; 
     835    return $self->is_crypted 
     836        ? $self->ballot_count_crypt 
     837        : $self->ballot_count_clear; 
     838} 
     839 
     840sub ballot_count_clear { 
     841    my ($self) = @_; 
     842 
     843    my $sth = $self->db->prepare_cached( 
     844        q{select count(*) from ballot where poll = ?} 
     845    ); 
     846 
     847    $sth->execute($self->voteid); 
     848    my $res = $sth->fetchrow_hashref; 
     849    $sth->finish; 
     850    $res->{count} 
     851} 
     852 
     853sub ballot_count_crypt { 
     854    my ($self) = @_; 
     855 
     856    my $sth = $self->db->prepare_cached( 
     857        q{select count(*) from ballot_enc where poll = ?} 
     858    ); 
     859 
     860    $sth->execute($self->voteid); 
     861    my $res = $sth->fetchrow_hashref; 
     862    $sth->finish; 
     863    $res->{count} 
     864} 
     865 
     866sub voting_count { 
     867    my ($self) = @_; 
     868 
     869    my $sth = $self->db->prepare_cached( 
     870        q{ 
     871        select count(*) from voting 
     872        where poll = ? 
     873        } 
     874    ); 
     875    $sth->execute($self->voteid); 
     876    my $res = $sth->fetchrow_hashref; 
     877    $sth->finish; 
     878    $res->{count} 
     879} 
     880 
     881sub signing_count { 
     882    my ($self) = @_; 
     883 
     884    my $sth = $self->db->prepare_cached( 
     885        q{ 
     886        select count(*) from signing join voting 
     887        on voting.key = signing.key where poll = ? 
     888        } 
     889    ); 
     890 
     891    $sth->execute($self->voteid); 
     892    my $res = $sth->fetchrow_hashref; 
     893    $sth->finish; 
     894    $res->{count} 
     895} 
     896 
     897sub not_signing_count { 
     898    my ($self) = @_; 
     899    my $sth = $self->db->prepare_cached( 
     900        q{ 
     901        select count(*) from voting where key 
     902        not in (select key from signing) 
     903        } 
     904    ); 
     905 
     906    $sth->execute($self->voteid); 
     907    my $res = $sth->fetchrow_hashref; 
     908    $sth->finish; 
     909    $res->{count} 
     910} 
     911 
    892912=head1 AUTHOR 
    893913 
Note: See TracChangeset for help on using the changeset viewer.