- Timestamp:
- 04/17/09 15:32:47 (15 years ago)
- Location:
- trunk/lib/Vote/DB
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/DB/Poll.pm
r213 r214 513 513 } 514 514 515 sub voting_count {516 my ($self) = @_;517 518 my $sth = $self->db->prepare_cached(519 q{520 select count(*) from voting521 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 voting536 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 546 515 sub is_crypted { 547 516 my ($self) = @_; 548 517 return $self->info->{public_key} ? 1 : 0; 549 }550 551 sub ballot_count {552 my ($self) = @_;553 return $self->is_crypted554 ? $self->ballot_count_crypt555 : $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}582 518 } 583 519 … … 890 826 $privkey 891 827 } 828 829 ######### 830 # Count # 831 ######### 832 833 sub ballot_count { 834 my ($self) = @_; 835 return $self->is_crypted 836 ? $self->ballot_count_crypt 837 : $self->ballot_count_clear; 838 } 839 840 sub 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 853 sub 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 866 sub 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 881 sub 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 897 sub 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 892 912 =head1 AUTHOR 893 913 -
trunk/lib/Vote/DB/Poll/Results.pm
r213 r214 27 27 sub absolute_majority { 28 28 my ($self) = @_; 29 my $ballot_count = $self-> ballot_count_nonull;29 my $ballot_count = $self->voices_ballot_count; 30 30 return int($ballot_count / 2) + 1; 31 31 } … … 48 48 } 49 49 50 sub ballot_count_nonull { 50 sub ballot_count_nonull {not_empty_ballot_count(@_)} 51 52 sub voices_ballot_count { 53 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 60 61 sub empty_ballot_count { 62 my ($self) = @_; 63 64 my $sth = $self->db->prepare_cached( 65 q{ 66 select count(*) from ballot where poll = ? 67 and id not in (select id from ballot_item) and 68 (invalid = 'false' or invalid is null) 69 } 70 ); 71 72 $sth->execute($self->voteid); 73 my $res = $sth->fetchrow_hashref; 74 $sth->finish; 75 $res->{count} 76 } 77 78 sub not_empty_ballot_count { 51 79 my ($self) = @_; 52 80 … … 75 103 } 76 104 105 sub results { 106 my ($self) = @_; 107 $self->_results( 108 $self->info('empty_ballot_has_voice') 109 ? 0 110 : 1 111 ); 112 } 113 77 114 sub _results { 78 115 my ($self, $nonull) = @_; … … 85 122 union 86 123 select ballot.id, coalesce(corrected, ballot_map.to, value) as "value" from ballot 87 } . ($nonull ? '' : ' left ') . q{ 88 join ballot_item 124 } . ($nonull ? '' : ' left ') . q{ join ballot_item 89 125 on ballot.id = ballot_item.id 90 126 left join ballot_map on ballot.poll = ballot_map.poll and ballot_map.from = ballot_item.value
Note: See TracChangeset
for help on using the changeset viewer.