Changeset 165 for trunk/lib


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

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.