Changeset 165


Ignore:
Timestamp:
04/06/09 02:13:06 (15 years ago)
Author:
nanardon
Message:
  • add Vote::DB::Choice object
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MANIFEST

    r164 r165  
    2727lib/Vote/DB/Voting.pm 
    2828lib/Vote/DB/Ballot.pm 
     29lib/Vote/DB/Choice.pm 
    2930lib/Vote/Model/Vote.pm 
    3031lib/Vote/Template/Plugin/Mail.pm 
  • trunk/lib/Vote/DB.pm

    r161 r165  
    1111use Vote::DB::Ballot; # see ballot() 
    1212use Vote::DB::Voting; # see delete_voting() 
     13use Vote::DB::Choice; 
    1314 
    1415=head1 NAME 
     
    146147} 
    147148 
    148 # Choice sub class ?? 
    149  
    150149sub choice_info { 
    151150    my ($self, $chid) = @_; 
    152     my $sth = $self->db->prepare_cached( 
    153         q{select * from choice where key = ?} 
    154     ); 
    155     $sth->execute($chid); 
    156     my $res = $sth->fetchrow_hashref; 
    157     $sth->finish; 
    158     $res 
    159 } 
    160  
    161 sub modify_choice { 
    162     my ($self, $chid, $label) = @_; 
    163  
    164     my $sth = $self->db->prepare_cached( 
    165         q{update choice set label = ? where key = ?} 
    166     ); 
    167     $sth->execute($label, $chid); 
     151    Vote::DB::Choice->new($self->{dbstring}, $chid)->info; 
    168152} 
    169153 
  • trunk/lib/Vote/DB/Poll.pm

    r161 r165  
    1010use Vote::DB::Ballot; 
    1111use Vote::DB::Voting; 
     12use Vote::DB::Choice; 
    1213 
    1314=head1 NAME 
     
    212213} 
    213214 
     215sub choice { 
     216    my ($self, $chid) = @_; 
     217     
     218    my $sth = $self->db->prepare_cached( 
     219        q{ 
     220        select key from choice where poll = ? and key = ? 
     221        } 
     222    ); 
     223    $sth->execute($self->voteid, $chid); 
     224    my $res = $sth->fetchrow_hashref; 
     225    $sth->finish; 
     226    return $res ? Vote::DB::Choice->new($self->{dbstring}, $chid) : undef; 
     227} 
     228 
    214229sub choices { 
    215230    my ($self) = @_; 
     
    242257 
    243258    1 
     259} 
     260 
     261sub delete_choice { 
     262    my ($self, $chid) = @_; 
     263 
     264    my $sth = $self->db->prepare_cached( 
     265        q{delete from choice where key = ?} 
     266    ); 
     267 
     268    $sth->execute($chid); 
    244269} 
    245270 
  • trunk/root/templates/includes/ballot_form.tt

    r164 r165  
    44 
    55<!-- $Id$ --> 
    6 [% FOREACH choice = poll.choices() %] 
    7 [% key = vote.choice_info(choice).key %] 
     6[% FOREACH key = poll.choices() %] 
     7[% choice = poll.choice(key) %] 
    88<input type="checkbox" name="sbal" value="[% key %]"[% " checked" IF sbal.$key %]> 
    9 [% vote.choice_info(choice).label | html %]<br> 
     9[% choice.info.label | html %]<br> 
    1010[% END %] 
    1111 
Note: See TracChangeset for help on using the changeset viewer.