Changeset 195


Ignore:
Timestamp:
04/14/09 20:02:56 (15 years ago)
Author:
nanardon
Message:
  • start new value mapping method
Location:
trunk
Files:
3 edited

Legend:

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

    r171 r195  
    6565 
    6666    my $sth = $self->db->prepare_cached( 
    67         q{select *, value as v from ballot_item where id = ?} 
     67        q{ 
     68        select ballot_item.*, value as v, 
     69        coalesce(ballot_map.to, corrected) as corrected 
     70        from ballot_item join ballot on ballot.id = ballot_item.id 
     71        left join ballot_map on ballot_map.poll = ballot.poll and 
     72        ballot_map.from = ballot_item.value 
     73        where ballot.id = ? 
     74        } 
    6875    ); 
    6976    $sth->execute($self->ballotid); 
  • trunk/lib/Vote/DB/Poll/Results.pm

    r193 r195  
    6767sub results_count { 
    6868    my ($self) = @_; 
     69    $self->_results(); 
     70} 
     71 
     72sub results_nonull { 
     73    my ($self) = @_; 
     74    $self->_results(1); 
     75} 
     76 
     77sub _results { 
     78    my ($self, $nonull) = @_; 
    6979 
    7080    my $sth = $self->db->prepare( 
    7181        q{ 
    7282        select count(ballot.id), value from 
    73         (select ballot.id, coalesce(corrected, value) as "value" from ballot left join ballot_item 
    74         on ballot.id = ballot_item.id where ballot.poll = ? and (invalid = 'false' or invalid is null) 
    75         group by ballot.id, coalesce(corrected, value)) as ballot 
     83        (select ballot.id, coalesce(corrected, ballot_map.to, value) as "value" from ballot 
     84        } . ($nonull ? '' : ' left ') . q{ 
     85        join ballot_item 
     86        on ballot.id = ballot_item.id  
     87        left join ballot_map on ballot.poll = ballot_map.poll and ballot_map.from = ballot_item.value 
     88        where ballot.poll = ? and (invalid = 'false' or invalid is null) 
     89        group by ballot.id, coalesce(corrected, ballot_map.to, value)) as ballot 
    7690        group by value 
    7791        order by count desc, value 
     
    8599    \@results; 
    86100} 
    87  
    88 sub results_nonull { 
    89     my ($self) = @_; 
    90  
    91     my $sth = $self->db->prepare( 
    92         q{ 
    93         select count(ballot.id), value from 
    94         (select ballot.id, coalesce(corrected, value) as "value" from ballot join ballot_item 
    95         on ballot.id = ballot_item.id where ballot.poll = ? and (invalid = 'false' or invalid is null) 
    96         group by ballot.id, coalesce(corrected, value)) as ballot 
    97         group by value 
    98         order by count desc, value 
    99         } 
    100     ); 
    101     $sth->execute($self->voteid); 
    102     my @results; 
    103     while (my $res = $sth->fetchrow_hashref) { 
    104         push(@results, $res); 
    105     } 
    106     \@results; 
    107 } 
    108  
    109101 
    110102=head1 AUTHOR 
Note: See TracChangeset for help on using the changeset viewer.