Changeset 20
- Timestamp:
- 03/08/09 15:36:06 (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Controller/Ballot.pm
r19 r20 64 64 $c->stash->{choices} = { %choices }; 65 65 $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; 66 $c->stash->{fsbal} = [ map {66 $c->stash->{fsbal} = [ grep { $_ } map { 67 67 s/^\s+//; 68 68 s/\s+$//; … … 71 71 } ($c->req->param('fsbal')) ]; 72 72 73 my @torecord = grep { $_ } ( 74 (map { $choices{$_} } $c->req->param('sbal')), 75 @{ $c->stash->{fsbal} } 76 ); 77 78 if (scalar(@torecord) > $vote->vote_info($id)->{choice_count}) { 73 my @sbalval = grep { $_ } map { $choices{$_} } $c->req->param('sbal'); 74 75 if (scalar(@sbalval) + scalar(@{$c->stash->{fsbal} || []}) 76 > $vote->vote_info($id)->{choice_count}) { 79 77 $c->req->param('ballot', ''); 80 78 $c->stash->{vote_error} = 'Seulement ' . … … 84 82 { 85 83 my %uniq; 86 $uniq{lc($_)} foreach(@torecord);87 if (scalar(keys %uniq) != scalar(@ torecord)) {84 $uniq{lc($_)} = 1 foreach(@sbalval, @{$c->stash->{fsbal} || []}); 85 if (scalar(keys %uniq) != scalar(@sbalval) + scalar(@{$c->stash->{fsbal} || []})) { 88 86 $c->req->param('ballot', ''); 89 87 $c->stash->{vote_error} = 'Une valeur est en double'; … … 96 94 $uid, 97 95 $id, 98 [ @torecord ], 96 [ @sbalval ], 97 [ @{ $c->stash->{fsbal} } ], 99 98 $c->req->address, 100 99 ); # TODO trap error -
trunk/lib/Vote/Model/Vote.pm
r15 r20 221 221 222 222 sub _register_ballot { 223 my ($self, $voteid, $choice ) = @_;223 my ($self, $voteid, $choice, $fchoice) = @_; 224 224 225 225 my $addb = $self->db->prepare_cached( 226 226 q{ 227 insert into ballot (id, poll ) values (?,?)227 insert into ballot (id, poll, invalid) values (?,?,?) 228 228 } 229 229 ); 230 230 my $uid = gen_uid; 231 $addb->execute($uid, $voteid ) or do {231 $addb->execute($uid, $voteid, scalar(@{$fchoice || []}) ? undef : 'f') or do { 232 232 self->db->rollback; 233 233 return; … … 236 236 my $addbc = $self->db->prepare_cached( 237 237 q{ 238 insert into ballot_item (id, value ) values (?,?)238 insert into ballot_item (id, value, fromlist) values (?,?,?) 239 239 } 240 240 ); 241 241 foreach (@{ $choice || []}) { 242 $addbc->execute($uid, $_ ) or do {242 $addbc->execute($uid, $_, 't') or do { 243 243 $self->db->rollback; 244 244 return; 245 245 }; 246 246 } 247 foreach (@{ $fchoice || []}) { 248 $addbc->execute($uid, $_, 'f') or do { 249 $self->db->rollback; 250 return; 251 }; 252 } 247 253 248 254 $uid; … … 250 256 251 257 sub register_ballot { 252 my ($self, $vid, $voteid, $choice, $ referal) = @_;258 my ($self, $vid, $voteid, $choice, $fchoice, $referal) = @_; 253 259 254 260 # First we register voting has voted … … 256 262 257 263 # registring choices 258 my $uid = $self->_register_ballot($voteid, $choice ) or return;264 my $uid = $self->_register_ballot($voteid, $choice, $fchoice) or return; 259 265 260 266 # everything went fine, saving!
Note: See TracChangeset
for help on using the changeset viewer.