Changeset 207 for trunk/lib/Vote


Ignore:
Timestamp:
04/16/09 02:33:03 (15 years ago)
Author:
nanardon
Message:
  • cleanup old functions and switch everything to new objects
Location:
trunk/lib/Vote
Files:
4 edited

Legend:

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

    r206 r207  
    4747    my $password = $c->session->{password} || $c->req->param('password'); 
    4848 
    49     if (!$c->model('Vote')->auth_voting($id, $mail, $password)) { 
     49    if (!$c->model('Vote')->poll($id)->auth_voting($mail, $password)) { 
    5050        $c->stash->{page}{title} = $poll->info('label') . ': Login'; 
    5151        $c->delete_session('invalid user/pass'); 
     
    7373    my $vote = $c->model('Vote'); 
    7474    my %choices; 
    75     foreach ($vote->vote_choices($id)) { 
    76         $choices{$vote->choice_info($_)->{key}} = $vote->choice_info($_)->{label}; 
     75    foreach ($poll->choices_keys) { 
     76        $choices{$_} = $poll->choice($_)->info->{label}; 
    7777    } 
    7878    $c->stash->{choices} = { %choices }; 
     
    111111 
    112112    if ($c->req->param('confirm')) { 
    113         $c->stash->{ballotid} = $vote->register_ballot( 
     113        $c->stash->{ballotid} = $poll->register_ballot( 
    114114            $mail, 
    115             $id, 
    116115            [ @sbalval ], 
    117116            [ @{ $c->stash->{fsbal} } ], 
  • trunk/lib/Vote/Controller/Vote.pm

    r206 r207  
    3838 
    3939    $c->stash->{voteid} = $id; 
    40     $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id).info('label'); 
     40    $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id)->info('label'); 
    4141} 
    4242 
  • trunk/lib/Vote/DB.pm

    r206 r207  
    88use Vote::DB::Poll; 
    99use Vote::DB::Poll::Results; 
    10 use Vote::DB::Ballot; # see ballot() 
    11 use Vote::DB::Voting; # see delete_voting() 
    12 use Vote::DB::Choice; 
    1310 
    1411our $VERSION = '1.90'; 
     
    10097} 
    10198 
    102 # TODO 
    103 sub ballot { 
    104     my ($self, $ballotid) = @_; 
    105     die "# ballot" . join(' ',caller()); 
    106     # TODO must die, ballot are attached to a poll 
    107     Vote::DB::Ballot->new($self->{dbstring}, $ballotid); 
    108 } 
    109  
    110 # TODO 
    111 sub vote_param { 
    112     my ($self, $voteid, %attr) = @_; 
    113     die "# vote_param" . join(' ',caller()); 
    114     $self->poll($voteid)->param(%attr); 
    115 } 
    116  
    117 # TODO kill this 
    118 sub vote_status { 
    119     my ($self, $id) = @_; 
    120     die "# vote_status" . join(' ',caller()); 
    121     $self->poll($id)->status; 
    122 } 
    123  
    124 # TODO 
    125 sub vote_info { 
    126     my ($self, $id) = @_; 
    127     die "# vote_info" . join(' ',caller()); 
    128     $self->poll($id)->info; 
    129 } 
    130  
    131 sub vote_set_settings { 
    132     my ($self, $poll, $var, $val) = @_; 
    133     $self->poll($poll)->set_settings($var, $val); 
    134 } 
    135  
    136 sub vote_signing { 
    137     my ($self, $id) = @_; 
    138     $self->poll($id)->signing; 
    139 } 
    140  
    141 sub vote_voting { 
    142     my ($self, $voteid) = @_; 
    143     $self->poll($voteid)->voting_keys; 
    144 } 
    145  
    146 sub voting_info { 
    147     my ($self, $id) = @_; 
    148     $self->poll($id)->voting_info; 
    149 } 
    150  
    151 sub vote_choices { 
    152     my ($self, $id) = @_; 
    153     $self->poll($id)->choices; 
    154 } 
    155  
    156 sub vote_add_choice { 
    157     my ($self, $voteid, $label) = @_; 
    158     $self->poll($voteid)->add_choice($label); 
    159 } 
    160  
    161 sub choice_info { 
    162     my ($self, $chid) = @_; 
    163     Vote::DB::Choice->new($self->{dbstring}, $chid)->info; 
    164 } 
    165  
    166 sub delete_choice { 
    167     my ($self, $chid) = @_; 
    168  
    169     my $sth = $self->db->prepare_cached( 
    170         q{delete from choice where key = ?} 
    171     ); 
    172  
    173     $sth->execute($chid); 
    174 } 
    175  
    176 sub voting_info_id { 
    177     my ($self, $mail, $voteid) = @_; 
    178     $self->poll($voteid)->voting_from_mail($mail)->info; 
    179 } 
    180  
    181 sub register_ballot { 
    182     my ($self, $vid, $voteid, $choice, $fchoice, $referal) = @_; 
    183     $self->poll($voteid)->register_ballot($vid, $choice, $fchoice, $referal); 
    184 } 
    185  
    186 sub vote_voting_count { 
    187     my ($self, $id) = @_; 
    188     $self->poll($id)->voting_count; 
    189 } 
    190  
     99# This part is keep to track error 
     100sub ballot {die "# ballot" . join(' ',caller());} 
     101sub vote_param { die "# vote_param" . join(' ',caller());} 
     102sub vote_status {die "# vote_status" . join(' ',caller());} 
     103sub vote_info {die "# vote_info" . join(' ',caller());} 
     104sub vote_set_settings {die "# old functions" . join(' ',caller());} 
     105sub vote_signing {die "# old functions" . join(' ',caller());} 
     106sub vote_voting {die "# old functions" . join(' ',caller());} 
     107sub voting_info {die "# old functions" . join(' ',caller());} 
     108sub vote_choices {die "# old functions" . join(' ',caller());} 
     109sub vote_add_choice {die "# old functions" . join(' ',caller());} 
     110sub choice_info {die "# old functions" . join(' ',caller());} 
     111sub delete_choice {die "# old functions" . join(' ',caller());} 
     112sub voting_info_id {die "# old functions" . join(' ',caller());} 
     113sub register_ballot {die "# old functions" . join(' ',caller());} 
     114sub vote_voting_count {die "# old functions" . join(' ',caller());} 
    191115sub signing_count { vote_signing_count(@_) } 
    192  
    193 sub vote_signing_count { 
    194     my ($self, $voteid) = @_; 
    195     $self->poll($voteid)->signing_count; 
    196 } 
    197  
     116sub vote_signing_count {die "# old functions" . join(' ',caller());} 
    198117sub ballot_count { vote_ballot_count(@_) } 
    199  
    200 sub vote_ballot_count { 
    201     my ($self, $voteid) = @_; 
    202     $self->poll($voteid)->ballot_count; 
    203 } 
    204  
     118sub vote_ballot_count {die "# old functions" . join(' ',caller());} 
    205119sub ballot_count_nonull { vote_ballot_count_nonull(@_) } 
    206  
    207 sub vote_ballot_count_nonull { 
    208     my ($self, $voteid) = @_; 
    209     $self->results($voteid)->ballot_count_nonull; 
    210 } 
    211  
    212 sub auth_voting { 
    213     my ($self, $poll, $mail, $password) = @_; 
    214     $self->poll($poll)->auth_voting($mail, $password); 
    215 } 
    216  
    217 sub auth_poll { 
    218     my ($self, $voteid, $passwd) = @_; 
    219     $self->poll($voteid)->auth_poll($passwd); 
    220 } 
    221  
    222 sub voting_has_sign { 
    223     my ($self, $poll, $user) = @_; 
    224     $self->poll($poll)->voting_has_sign($user); 
    225 } 
    226  
    227 # Requete de decompte des voix: 
    228  
    229 sub vote_results_count { 
    230     my ($self, $voteid) = @_; 
    231     $self->results($voteid)->results_count; 
    232 } 
    233  
    234 sub vote_results_nonull { 
    235     my ($self, $voteid) = @_; 
    236     $self->results($voteid)->results_nonull; 
    237 } 
    238  
    239 sub list_vote_ballot { 
    240     my ($self, $voteid) = @_; 
    241     $self->poll($voteid)->list_ballot; 
    242 } 
    243  
    244 sub list_vote_ballot_needvalid { 
    245     my ($self, $voteid) = @_; 
    246     $self->poll($voteid)->list_ballot_needvalid; 
    247 } 
    248  
    249 sub ballot_info { 
    250     my ($self, $ballotid) = @_; 
    251     $self->ballot($ballotid)->info; 
    252 } 
    253  
    254 sub mark_ballot_invalid { 
    255     my ($self, $ballotid, $invalid) = @_; 
    256     $self->ballot($ballotid)->mark_invalid($invalid); 
    257 } 
    258  
    259 sub ballot_items { 
    260     my ($self, $ballotid) = @_; 
    261     $self->ballot($ballotid)->items; 
    262 } 
    263  
    264 sub vote_ballot_untrusted_values { 
    265     my ($self, $voteid) = @_; 
    266     $self->poll($voteid)->ballot_untrusted_values; 
    267 } 
    268  
    269 sub vote_ballot_values { 
    270     my ($self, $voteid) = @_; 
    271     $self->poll($voteid)->ballot_values; 
    272 } 
    273  
    274 sub vote_map_value { 
    275     my ($self, $voteid, $from, $to) = @_; 
    276     $self->poll($voteid)->map_value($from, $to); 
    277 } 
    278  
    279 sub addupd_voting { 
    280     my ($self, $voteid, $mail, $id) = @_; 
    281     $self->poll($voteid)->addupd_voting($mail, $id); 
    282 } 
    283  
    284 sub delete_voting { 
    285     my ($self, $key) = @_; 
    286     # must die, voting are attached to a poll 
    287     Vote::DB::Voting->new($self->{dbstring}, $key)->has_sign and return; 
    288     my $sth = $self->db->prepare_cached( 
    289         q{delete from voting where key = ?} 
    290     ); 
    291  
    292     $sth->execute($key); 
    293 } 
    294  
    295 sub voting_from_file { 
    296     my ($self, $voteid, $fh, $delete) = @_; 
    297     $self->poll($voteid)->voting_from_file($fh, $delete); 
    298 } 
     120sub vote_ballot_count_nonull {die "# old functions" . join(' ',caller());} 
     121sub auth_voting {die "# old functions" . join(' ',caller());} 
     122sub auth_poll {die "# old functions" . join(' ',caller());} 
     123sub voting_has_sign {die "# old functions" . join(' ',caller());} 
     124sub vote_results_count {die "# old functions" . join(' ',caller());} 
     125sub vote_results_nonull {die "# old functions" . join(' ',caller());} 
     126sub list_vote_ballot {die "# old functions" . join(' ',caller());} 
     127sub list_vote_ballot_needvalid {die "# old functions" . join(' ',caller());} 
     128sub ballot_info {die "# vote_status" . join(' ',caller());} 
     129sub mark_ballot_invalid {die "# old functions" . join(' ',caller());} 
     130sub ballot_items {die "# old functions" . join(' ',caller());} 
     131sub vote_ballot_untrusted_values {die "# old functions" . join(' ',caller());} 
     132sub vote_ballot_values {die "# old functions" . join(' ',caller());} 
     133sub vote_map_value {die "# old functions" . join(' ',caller());} 
     134sub addupd_voting {die "# old functions" . join(' ',caller());} 
     135sub delete_voting {die "# old functions" . join(' ',caller());} 
     136sub voting_from_file {die "# old functions" . join(' ',caller());} 
    299137 
    300138sub clean_old_poll_request { 
    301139    my ($self) = @_; 
    302  
    303140    $self->db->do(q{delete from poll_request where "create" < now() - '30 days'::interval}); 
    304141} 
  • trunk/lib/Vote/DB/Poll.pm

    r206 r207  
    2929    my ($class, $dbstring, $voteid) = @_; 
    3030     
     31    $voteid or return; 
     32 
    3133    bless { 
    3234        voteid => $voteid, 
     
    135137    if ($var) { 
    136138        if (grep { $var eq $_ } (_online_f(), qw(dstart hstart dend hend))) { 
    137             return $self->_info->{$var}; 
     139            return ( $self->_info || {} )->{$var}; 
    138140        } else { 
    139141            my $sth = $self->db->prepare_cached( 
     
    276278} 
    277279 
     280sub choices_keys { 
     281    my ($self) = @_; 
     282 
     283    my $sth = $self->db->prepare_cached( 
     284        q{ 
     285        select key from choice where poll = ? 
     286        order by label 
     287        } 
     288    ); 
     289    $sth->execute($self->voteid); 
     290    my @ch; 
     291    while (my $res = $sth->fetchrow_hashref) { 
     292        push(@ch, $res->{key}); 
     293    } 
     294    @ch 
     295} 
     296 
     297# TODO: replaced, to kill 
    278298sub choices { 
    279299    my ($self) = @_; 
     
    636656} 
    637657 
     658# TODO kill this: 
    638659sub list_ballot { 
     660    ballot_keys(@_); 
     661} 
     662 
     663sub ballot_keys { 
    639664    my ($self) = @_; 
    640665 
     
    796821    } 
    797822    1; 
     823} 
     824 
     825sub delete_voting { 
     826    my ($self, $key) = @_; 
     827    $self->voting($key)->has_sign and return; 
     828    my $sth = $self->db->prepare_cached( 
     829        q{delete from voting where key = ? and poll = ?} 
     830    ); 
     831 
     832    $sth->execute($key, $self->voteid); 
    798833} 
    799834 
Note: See TracChangeset for help on using the changeset viewer.