Changeset 224


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

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Controller/Admin.pm

    r221 r224  
    122122 
    123123    /^AFTER$/ and do { 
    124         if ($c->req->param('mapfrom') && $c->req->param('mapto')) { 
     124        if ($c->req->param('mapfrom')) { 
    125125            $poll->map_value( 
    126                 $id, 
    127126                $c->req->param('mapfrom'), 
    128                 $c->req->param('mapto'), 
     127                $c->req->param('mapto') || undef, 
    129128            ); 
    130129        } 
  • 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} 
  • trunk/root/templates/admin/includes/ballot_validation.tt

    r223 r224  
    1616    <input type="hidden" name="mapfrom" value="[% untrusted | html %]"> 
    1717    <select name="mapto"> 
     18    <option></option> 
    1819    [% FOREACH v = poll.ballot_values %] 
    1920        [% NEXT IF v == untrusted %] 
    20         <option>[% v | html %]</options> 
     21        <option[% " selected" IF poll.value_map_to(untrusted) == v %]>[% v | html %]</options> 
    2122    [% END %] 
    2223    </select> 
Note: See TracChangeset for help on using the changeset viewer.