Changeset 22 for trunk/lib/Vote/Model/Vote.pm
- Timestamp:
- 03/09/09 03:59:15 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Model/Vote.pm
r21 r22 172 172 my $sth = $self->db->prepare_cached( 173 173 q{ 174 select *from choice where poll = ?174 select key from choice where poll = ? 175 175 order by label 176 176 } … … 179 179 my @ch; 180 180 while (my $res = $sth->fetchrow_hashref) { 181 push(@ch, $res );181 push(@ch, $res->{key}); 182 182 } 183 183 @ch 184 } 185 186 sub choice_info { 187 my ($self, $chid) = @_; 188 my $sth = $self->db->prepare_cached( 189 q{select * from choice where key = ?} 190 ); 191 $sth->execute($chid); 192 my $res = $sth->fetchrow_hashref; 193 $sth->finish; 194 $res 195 } 196 197 sub vote_add_choice { 198 my ($self, $voteid, $label) = @_; 199 200 my $sth = $self->db->prepare_cached( 201 q{insert into choice (poll, label) values (?,?)} 202 ); 203 204 $sth->execute($voteid, $label) or do { 205 $self->db->rollback; 206 return; 207 }; 208 209 1 210 } 211 212 sub modify_choice { 213 my ($self, $chid, $label) = @_; 214 215 my $sth = $self->db->prepare_cached( 216 q{update choice set label = ? where key = ?} 217 ); 218 $sth->execute($label, $chid); 219 } 220 221 sub delete_choice { 222 my ($self, $chid) = @_; 223 224 my $sth = $self->db->prepare_cached( 225 q{delete from choice where key = ?} 226 ); 227 228 $sth->execute($chid); 184 229 } 185 230 … … 448 493 } 449 494 495 sub addupd_voting { 496 my ($self, $voteid, $id, $mail) = @_; 497 498 my $upd = $self->db->prepare_cached( 499 q{ 500 update voting set mail = ? where poll = ? and id = ? 501 } 502 ); 503 504 if ($upd->execute($mail, $voteid, $id) == 0) { 505 my $add = $self->db->prepare_cached(q{ 506 insert into voting (poll, id, mail) values (?,?,?) 507 }); 508 509 $add->execute($voteid, $id, $mail); 510 } 511 } 512 513 sub voting_from_file { 514 my ($self, $voteid, $fh, $delete) = @_; 515 516 if ($delete) { 517 my $sth = $self->db->prepare(q{delete from voting where poll = ?}); 518 $sth->execute($voteid); 519 } 520 521 while (my $line = <$fh>) { 522 chomp($line); 523 warn $line; 524 my ($id, $mail) = split(';', $line); 525 $id && $mail or do { 526 $self->db->rollback; 527 return; 528 }; 529 $self->addupd_voting($voteid, $id, $mail); 530 } 531 1; 532 } 533 450 534 451 535 =head1 AUTHOR
Note: See TracChangeset
for help on using the changeset viewer.