Changeset 269 for trunk/lib/Epoll
- Timestamp:
- 12/12/09 19:40:32 (15 years ago)
- Location:
- trunk/lib/Epoll
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Epoll/Controller/Admin.pm
r267 r269 296 296 } 297 297 298 sub delete: LocalRegex('^(\w+)/delete$') { 299 my ($self, $c) = @_; 300 ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; 301 my $poll = $c->model('Vote')->results($c->stash->{voteid}); 302 303 $poll->info or do { 304 $c->res->redirect($c->uri_for('/')); 305 return; 306 }; 307 308 $c->forward('auth') or return; 309 310 if ($c->req->param('delete_ballot')) { 311 $c->stash->{template} = 'admin/delete_ballot_confirm.tt'; 312 return; 313 } 314 315 if ($c->req->param('delete_ballot_confirm')) { 316 $poll->delete_ballots; 317 $c->response->redirect($c->uri_for($poll->uid)); 318 } 319 } 320 298 321 sub ajaxsettings: LocalRegex('^(\w+)/ajaxsettings$') { 299 322 my ($self, $c) = @_; -
trunk/lib/Epoll/DB/Poll.pm
r267 r269 997 997 } 998 998 999 ################# 1000 # CLEANING DATA # 1001 ################# 1002 1003 sub _delete_ballot { 1004 my ($self) = @_; 1005 1006 foreach ( 1007 q{delete from ballot_item where id in (select id from ballot where 1008 ballot.poll = ?)}, 1009 q{delete from ballot where poll = ?}, 1010 q{delete from ballot_enc where poll = ?},) { 1011 my $req = $self->db->prepare($_); 1012 $req->execute($self->voteid) or return; 1013 } 1014 1015 return 1; 1016 } 1017 999 1018 =head1 AUTHOR 1000 1019 -
trunk/lib/Epoll/DB/Poll/Results.pm
r250 r269 6 6 use warnings; 7 7 use base 'Epoll::DB::Poll'; 8 use XML::Simple; 9 use vars qw($AUTOLOAD); 8 10 9 11 =head1 NAME … … 18 20 19 21 sub new { 20 my ($class, %args) = @_; 21 22 my $res = $class->SUPER::new(%args); 23 24 return bless $res, $class; 25 } 26 27 sub absolute_majority { 22 my ($class, @args) = @_; 23 24 my $res = $class->SUPER::new(@args); 25 26 $res = bless $res, $class; 27 $res->load_static_data; 28 $res 29 } 30 31 sub AUTOLOAD { 32 my ($self, @args) = @_; 33 my ($constname, $sub) = $AUTOLOAD =~ m/(.*)::([^:]+)/; 34 $sub =~ /^__(.*)/ and die "No sub $1"; 35 if ($self->{static_results}) { 36 return $self->{static_results}{$sub}; 37 } else { 38 my $realsub = "__$sub"; 39 return $self->$realsub(@args); 40 } 41 } 42 43 sub DESTROY {} 44 45 sub load_static_data { 46 my ($self) = @_; 47 if (my $res = $self->info('static_results')) { 48 $self->{static_results} = XMLin( 49 $res, 50 ForceArray => ['results'] 51 ); 52 } 53 } 54 55 sub ballot_count { 56 my ($self) = @_; 57 if ($self->{static_results}) { 58 return $self->{static_results}{ballot_count}; 59 } else { 60 return $self->SUPER::ballot_count(); 61 } 62 } 63 64 sub __absolute_majority { 28 65 my ($self) = @_; 29 66 my $ballot_count = $self->voices_ballot_count; … … 31 68 } 32 69 33 sub abstention {70 sub __abstention { 34 71 my ($self) = @_; 35 72 … … 48 85 } 49 86 50 sub ballot_count_nonull {not_empty_ballot_count(@_)}51 52 sub voices_ballot_count {87 sub __ballot_count_nonull {not_empty_ballot_count(@_)} 88 89 sub __voices_ballot_count { 53 90 my ($self) = @_; 54 91 return $self->info('empty_ballot_has_voice') … … 57 94 } 58 95 59 sub valid_ballot_count {96 sub __valid_ballot_count { 60 97 my ($self) = @_; 61 98 … … 73 110 } 74 111 75 sub invalid_ballot_count {112 sub __invalid_ballot_count { 76 113 my ($self) = @_; 77 114 … … 89 126 } 90 127 91 sub empty_ballot_count {128 sub __empty_ballot_count { 92 129 my ($self) = @_; 93 130 … … 106 143 } 107 144 108 sub not_empty_ballot_count {145 sub __not_empty_ballot_count { 109 146 my ($self) = @_; 110 147 … … 133 170 } 134 171 135 sub results {172 sub __results { 136 173 my ($self) = @_; 137 174 $self->_results( … … 190 227 } 191 228 229 sub dump_results { 230 my ($self) = @_; 231 my $xml = XML::Simple->new(ForceArray => 1, RootName => 'results'); 232 my %results; 233 234 foreach my $val (qw( 235 ballot_count 236 ), 237 map { s/^__//; $_ } grep { /^__/ } keys %{Epoll::DB::Poll::Results::} 238 ) { 239 $results{$val} = $self->$val(); 240 } 241 $xml->XMLout({ 242 %results 243 }); 244 } 245 246 sub delete_ballots { 247 my ($self) = @_; 248 249 $self->param('static_results' => $self->dump_results); 250 $self->_delete_ballot; 251 $self->commit; 252 $self->{static_results} = XMLin( 253 $self->info('static_results'), 254 ForceArray => ['results'] 255 ); 256 } 257 192 258 =head1 AUTHOR 193 259
Note: See TracChangeset
for help on using the changeset viewer.