Ignore:
Timestamp:
04/20/09 05:45:33 (15 years ago)
Author:
nanardon
Message:
  • always allow to remap ballot value (#12)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/DB/Poll.pm

    r219 r224  
    573573        select value from ballot join ballot_item 
    574574        on ballot.id = ballot_item.id 
    575         where poll = ? and fromlist = false and corrected is null 
     575        where poll = ? and fromlist = false 
    576576        group by value order by value 
    577577        } 
     
    604604} 
    605605 
     606sub value_map_to { 
     607    my ($self, $from) = @_; 
     608    my $sth = $self->db->prepare_cached( 
     609        q{select "to" from ballot_map where poll = ? and "from" = ?} 
     610    ); 
     611    $sth->execute($self->voteid, $from); 
     612    my $res = $sth->fetchrow_hashref; 
     613    $sth->finish; 
     614    $res->{to} 
     615} 
     616 
    606617sub map_value { 
    607618    my ($self, $from, $to) = @_; 
    608619 
    609     my $sth = $self->db->prepare_cached( 
    610         q{ 
    611         insert into ballot_map (poll, "from", "to") values (?,?,?) 
    612         } 
    613     ); 
    614  
    615     $sth->execute($self->voteid, $from, $to) or $self->rollback; 
     620    if (!$to) { 
     621        my $sth = $self->db->prepare_cached( 
     622            q{delete from ballot_map where poll = ? and "from" = ?} 
     623        ); 
     624        $sth->execute($self->voteid, $from); 
     625    } else { 
     626        my $sthup = $self->db->prepare_cached( 
     627            q{update ballot_map set "to" = ? where poll = ? and "from" = ?} 
     628        ); 
     629        if ($sthup->execute($to, $self->voteid, $from) == 0) { 
     630            my $sth = $self->db->prepare_cached( 
     631                q{ 
     632                insert into ballot_map (poll, "from", "to") values (?,?,?) 
     633                } 
     634            ); 
     635 
     636            $sth->execute($self->voteid, $from, $to) or $self->rollback; 
     637        } 
     638    } 
    616639    $self->commit; 
    617640} 
Note: See TracChangeset for help on using the changeset viewer.