Ignore:
Timestamp:
03/09/09 03:59:15 (15 years ago)
Author:
nanardon
Message:
  • admin page
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Model/Vote.pm

    r21 r22  
    172172    my $sth = $self->db->prepare_cached( 
    173173        q{ 
    174         select * from choice where poll = ? 
     174        select key from choice where poll = ? 
    175175        order by label 
    176176        } 
     
    179179    my @ch; 
    180180    while (my $res = $sth->fetchrow_hashref) { 
    181         push(@ch, $res); 
     181        push(@ch, $res->{key}); 
    182182    } 
    183183    @ch 
     184} 
     185 
     186sub 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 
     197sub 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 
     212sub 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 
     221sub 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); 
    184229} 
    185230 
     
    448493} 
    449494 
     495sub 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 
     513sub 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 
    450534 
    451535=head1 AUTHOR 
Note: See TracChangeset for help on using the changeset viewer.