Changeset 207 for trunk/lib/Vote
- Timestamp:
- 04/16/09 02:33:03 (15 years ago)
- Location:
- trunk/lib/Vote
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Controller/Ballot.pm
r206 r207 47 47 my $password = $c->session->{password} || $c->req->param('password'); 48 48 49 if (!$c->model('Vote')-> auth_voting($id,$mail, $password)) {49 if (!$c->model('Vote')->poll($id)->auth_voting($mail, $password)) { 50 50 $c->stash->{page}{title} = $poll->info('label') . ': Login'; 51 51 $c->delete_session('invalid user/pass'); … … 73 73 my $vote = $c->model('Vote'); 74 74 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}; 77 77 } 78 78 $c->stash->{choices} = { %choices }; … … 111 111 112 112 if ($c->req->param('confirm')) { 113 $c->stash->{ballotid} = $ vote->register_ballot(113 $c->stash->{ballotid} = $poll->register_ballot( 114 114 $mail, 115 $id,116 115 [ @sbalval ], 117 116 [ @{ $c->stash->{fsbal} } ], -
trunk/lib/Vote/Controller/Vote.pm
r206 r207 38 38 39 39 $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'); 41 41 } 42 42 -
trunk/lib/Vote/DB.pm
r206 r207 8 8 use Vote::DB::Poll; 9 9 use Vote::DB::Poll::Results; 10 use Vote::DB::Ballot; # see ballot()11 use Vote::DB::Voting; # see delete_voting()12 use Vote::DB::Choice;13 10 14 11 our $VERSION = '1.90'; … … 100 97 } 101 98 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 100 sub ballot {die "# ballot" . join(' ',caller());} 101 sub vote_param { die "# vote_param" . join(' ',caller());} 102 sub vote_status {die "# vote_status" . join(' ',caller());} 103 sub vote_info {die "# vote_info" . join(' ',caller());} 104 sub vote_set_settings {die "# old functions" . join(' ',caller());} 105 sub vote_signing {die "# old functions" . join(' ',caller());} 106 sub vote_voting {die "# old functions" . join(' ',caller());} 107 sub voting_info {die "# old functions" . join(' ',caller());} 108 sub vote_choices {die "# old functions" . join(' ',caller());} 109 sub vote_add_choice {die "# old functions" . join(' ',caller());} 110 sub choice_info {die "# old functions" . join(' ',caller());} 111 sub delete_choice {die "# old functions" . join(' ',caller());} 112 sub voting_info_id {die "# old functions" . join(' ',caller());} 113 sub register_ballot {die "# old functions" . join(' ',caller());} 114 sub vote_voting_count {die "# old functions" . join(' ',caller());} 191 115 sub signing_count { vote_signing_count(@_) } 192 193 sub vote_signing_count { 194 my ($self, $voteid) = @_; 195 $self->poll($voteid)->signing_count; 196 } 197 116 sub vote_signing_count {die "# old functions" . join(' ',caller());} 198 117 sub ballot_count { vote_ballot_count(@_) } 199 200 sub vote_ballot_count { 201 my ($self, $voteid) = @_; 202 $self->poll($voteid)->ballot_count; 203 } 204 118 sub vote_ballot_count {die "# old functions" . join(' ',caller());} 205 119 sub 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 } 120 sub vote_ballot_count_nonull {die "# old functions" . join(' ',caller());} 121 sub auth_voting {die "# old functions" . join(' ',caller());} 122 sub auth_poll {die "# old functions" . join(' ',caller());} 123 sub voting_has_sign {die "# old functions" . join(' ',caller());} 124 sub vote_results_count {die "# old functions" . join(' ',caller());} 125 sub vote_results_nonull {die "# old functions" . join(' ',caller());} 126 sub list_vote_ballot {die "# old functions" . join(' ',caller());} 127 sub list_vote_ballot_needvalid {die "# old functions" . join(' ',caller());} 128 sub ballot_info {die "# vote_status" . join(' ',caller());} 129 sub mark_ballot_invalid {die "# old functions" . join(' ',caller());} 130 sub ballot_items {die "# old functions" . join(' ',caller());} 131 sub vote_ballot_untrusted_values {die "# old functions" . join(' ',caller());} 132 sub vote_ballot_values {die "# old functions" . join(' ',caller());} 133 sub vote_map_value {die "# old functions" . join(' ',caller());} 134 sub addupd_voting {die "# old functions" . join(' ',caller());} 135 sub delete_voting {die "# old functions" . join(' ',caller());} 136 sub voting_from_file {die "# old functions" . join(' ',caller());} 299 137 300 138 sub clean_old_poll_request { 301 139 my ($self) = @_; 302 303 140 $self->db->do(q{delete from poll_request where "create" < now() - '30 days'::interval}); 304 141 } -
trunk/lib/Vote/DB/Poll.pm
r206 r207 29 29 my ($class, $dbstring, $voteid) = @_; 30 30 31 $voteid or return; 32 31 33 bless { 32 34 voteid => $voteid, … … 135 137 if ($var) { 136 138 if (grep { $var eq $_ } (_online_f(), qw(dstart hstart dend hend))) { 137 return $self->_info->{$var};139 return ( $self->_info || {} )->{$var}; 138 140 } else { 139 141 my $sth = $self->db->prepare_cached( … … 276 278 } 277 279 280 sub 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 278 298 sub choices { 279 299 my ($self) = @_; … … 636 656 } 637 657 658 # TODO kill this: 638 659 sub list_ballot { 660 ballot_keys(@_); 661 } 662 663 sub ballot_keys { 639 664 my ($self) = @_; 640 665 … … 796 821 } 797 822 1; 823 } 824 825 sub 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); 798 833 } 799 834
Note: See TracChangeset
for help on using the changeset viewer.