Changeset 207
- Timestamp:
- 04/16/09 02:33:03 (15 years ago)
- Location:
- trunk
- Files:
-
- 12 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 -
trunk/root/latex/poll_report.tt
r193 r207 94 94 \subsection{Liste des bulletins} 95 95 96 [% FOREACH id = poll.list_ballot %] 97 [% invalid = '#' _ vote.ballot_info(id).invalid %] 96 [% FOREACH id = poll.ballot_keys %] 97 [%- ballot = poll.ballot(id) -%] 98 [% invalid = '#' _ ballot.info.invalid %] 98 99 [% IF loop.first %] 99 100 \begin{enumerate} … … 101 102 \item \verb+[% id %]+ [% "\textbf{invalidé}" IF invalid == '#1' %] 102 103 103 [%- ballot = poll.ballot(id) -%]104 104 [%- FOREACH item = ballot.items -%] 105 105 [% '\begin{enumerate}' IF loop.first %] -
trunk/root/templates/admin/ballot.tt
r169 r207 3 3 [% vote = c.model('Vote') %] 4 4 [% poll = c.model('Vote').poll(voteid) %] 5 [% thisvote = poll.info %]6 5 7 6 <div style="float: left; width: 35%" class="box"> 8 7 <form action="[% c.uri_for(voteid, 'ballot') %]"> 9 8 Nombre de choix possible: 10 <input type="text" name="choice_count" value="[% c.req.param('choice_count') || thisvote.choice_count| html %]">9 <input type="text" name="choice_count" value="[% c.req.param('choice_count') || poll.info('choice_count') | html %]"> 11 10 <br> 12 11 Nombre de choix libres: 13 <input type="text" name="free_choice" value="[% c.req.param('free_choice') || thisvote.free_choice|| 0 | html %]">12 <input type="text" name="free_choice" value="[% c.req.param('free_choice') || poll.info('free_choice') || 0 | html %]"> 14 13 <br> 15 14 <input type="submit" name="pollparam" value="Enregistrer"> … … 18 17 <hr> 19 18 20 [% IF ! vote.vote_choices(voteid).size %]19 [% IF ! poll.choices_keys.size %] 21 20 <p class="alert">Aucun choix configuré</p> 22 21 [% ELSE %] 23 [% FOREACH choice = vote.vote_choices(voteid) %] 22 [% FOREACH choicek = poll.choices_keys %] 23 [% choice = poll.choice(choicek) %] 24 24 <form action="[% c.uri_for(voteid, 'ballot') %]" method="POST"> 25 [% loop.count %] - [% vote.choice_info(choice).label | html %]26 <input type="hidden" name="delch" value="[% vote.choice_info(choice).key%]">25 [% loop.count %] - [% choice.info.label | html %] 26 <input type="hidden" name="delch" value="[% choicek %]"> 27 27 <input type="submit" name="del" value="Effacer"> 28 28 </form> -
trunk/root/templates/admin/includes/ballot_validation.tt
r176 r207 3 3 4 4 [% IF poll.status == 'AFTER' %] 5 [% FOREACH untrusted = vote.vote_ballot_untrusted_values(voteid)%]5 [% FOREACH untrusted = poll.ballot_untrusted_values %] 6 6 [% IF loop.first %] 7 7 <div id="map_ballot"> … … 16 16 <input type="hidden" name="mapfrom" value="[% untrusted | html %]"> 17 17 <select name="mapto"> 18 [% FOREACH v = vote.vote_ballot_values(voteid)%]18 [% FOREACH v = poll.ballot_values %] 19 19 [% NEXT IF v == untrusted %] 20 20 <option>[% v | html %]</options> … … 31 31 [% END %] 32 32 33 [% FOREACH bid = vote.list_vote_ballot_needvalid(voteid) %]33 [% FOREACH bid = poll.list_ballot_needvalid(voteid) %] 34 34 [% IF loop.first %] 35 35 <div id="ballot_to_valid"> … … 41 41 <td>[% bid %]</td> 42 42 <td> 43 [% FOREACH item = vote.ballot_items(bid)%]43 [% FOREACH item = poll.ballot(bid).items %] 44 44 [% loop.count %]- [% item.v %]<br> 45 45 [% END %] -
trunk/root/templates/admin/index.tt
r206 r207 1 1 [% vote = c.model('Vote') %] 2 [% poll = c.model('Vote').poll( 'voteid') %]2 [% poll = c.model('Vote').poll(voteid) %] 3 3 4 4 [% FOREACH voteid = c.model('Vote').list_comming_vote %] 5 <a href="[% c.uri_for('/admin', voteid) %]">[% c.model('Vote').poll('voteid').info('label') | html %]</a>5 <a href="[% c.uri_for('/admin', voteid) %]">[% poll.info('label') | html %]</a> 6 6 <br> 7 7 [% END %] -
trunk/root/templates/admin/voting.tt
r205 r207 33 33 <div class="box" style="float: right; width: 60%;"> 34 34 35 [% IF NOT vote.vote_voting_count(voteid)%]35 [% IF NOT poll.voting_count %] 36 36 <p class="alert">Aucun votant inscrit</p> 37 37 [% ELSE %] 38 38 39 [% signing = vote.vote_voting(voteid) %] 40 41 [% FOREACH thisvoting = signing %] 39 [% FOREACH votingkey = poll.voting_keys %] 40 [% voting = poll.voting(votingkey) %] 42 41 43 42 [% IF loop.first %] … … 45 44 [% END %] 46 45 47 [% voting = vote.voting_info(thisvoting) %]48 46 <tr> 49 47 50 [% IF NOT voting. date %]48 [% IF NOT voting.info.date %] 51 49 [% IF poll.status != 'AFTER' %] 52 50 <form action="[% c.uri_for(voteid, 'voting') %]" method="POST"> 53 <input type="hidden" name="delvoting" value="[% voting.v key %]">51 <input type="hidden" name="delvoting" value="[% voting.votingkey %]"> 54 52 [% END %] 55 53 [% END %] 56 54 57 <td>[% voting.label | html %] [% voting. mail | html %]</td>58 <td>[% IF voting. passwd %]<i>(pass envoyé)</i>[% END %]</td>55 <td>[% voting.label | html %] [% voting.info.mail | html %]</td> 56 <td>[% IF voting.info.passwd %]<i>(pass envoyé)</i>[% END %]</td> 59 57 60 [% IF NOT voting. date %]58 [% IF NOT voting.info.date %] 61 59 <td> 62 60 [% IF poll.status != 'AFTER' %] … … 66 64 </form> 67 65 [% ELSE %] 68 <td>[% voting. date %]</td>66 <td>[% voting.info.date %]</td> 69 67 [% END %] 70 68 -
trunk/root/templates/default.tt
r206 r207 47 47 [% END %] 48 48 <tr> 49 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td> </td>49 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td> 50 50 </tr> 51 51 [% IF loop.last %] -
trunk/root/templates/includes/ballot_form.tt
r169 r207 1 1 [% poll = c.model('Vote').poll(voteid) %] 2 [% thisvote = poll.info() %]3 2 4 3 <!-- $Id$ --> … … 10 9 11 10 [% count = 0 %] 12 [% WHILE count < thisvote.free_choice%]11 [% WHILE count < poll.info('free_choice') %] 13 12 <input type="text" name="fsbal" value="[% fsbal.$count %]"><br> 14 13 [% count = count + 1 %] -
trunk/root/templates/includes/poll_results.tt
r206 r207 1 1 [% vote = c.model('Vote') %] 2 [% poll = c.model('Vote'). poll(voteid) %]2 [% poll = c.model('Vote').results(voteid) %] 3 3 4 4 [% IF poll.can_show_result %] … … 8 8 <a href="[% c.uri_for('/vote', voteid, 'report.pdf') %]">Rapport en PDF</a> 9 9 </div> 10 [% IF vote.list_vote_ballot_needvalid(voteid).size %]10 [% IF poll.list_ballot_needvalid.size %] 11 11 <p>Resultats provisoires:</p> 12 12 <p class="alert">Le gestionnaire doit vérifier la validité de certains bulletins</p> … … 15 15 [% END %] 16 16 <p>Nombre de choix à retenir: [% poll.info('choice_count') %]</p> 17 <p>Participations: [% vote.vote_signing_count(voteid) %] / [% vote.vote_voting_count(voteid)%]18 [% IF vote.vote_voting_count(voteid)%]19 ([% vote.vote_signing_count(voteid) * 100 / vote.vote_voting_count(voteid) | format('%.2f') %])17 <p>Participations: [% poll.signing_count %] / [% poll.voting_count %] 18 [% IF poll.voting_count %] 19 ([% poll.signing_count * 100 / poll.voting_count(voteid) | format('%.2f') %]) 20 20 [% END %]</p> 21 <p>Nombre de vote(s) exprimé(s): [% vote.vote_ballot_count_nonull(voteid)%]22 [% IF vote.vote_ballot_count(voteid) %]23 ([% vote.vote_ballot_count_nonull(voteid) * 100 / vote.vote_ballot_count(voteid)| format('%.2f') %]%)21 <p>Nombre de vote(s) exprimé(s): [% poll.ballot_count_nonull %] 22 [% IF poll.ballot_count(voteid) %] 23 ([% poll.ballot_count_nonull * 100 / poll.ballot_count | format('%.2f') %]%) 24 24 [% END %] 25 25 </p> 26 26 27 [% IF vote.vote_ballot_count_nonull(voteid)%]28 [% FOREACH res = vote.vote_results_nonull(voteid)%]27 [% IF poll.ballot_count_nonull %] 28 [% FOREACH res = poll.results_nonull %] 29 29 [% IF loop.first %] 30 30 <p>Score:</p> … … 43 43 [% mycount = loop.count %] 44 44 [% IF loop.count <= poll.info('choice_count') %] 45 [% IF res.count >= vote.absolute_majority %]45 [% IF res.count >= poll.absolute_majority %] 46 46 [% class = 'majabs' %] 47 47 [% ELSE %] … … 57 57 <td>[% res.value | html %]</td> 58 58 <td>[% res.count %]</td> 59 <td>[% res.count * 100 / vote.ballot_count_nonull(voteid)| format('%.2f') %]</td>59 <td>[% res.count * 100 / poll.ballot_count_nonull | format('%.2f') %]</td> 60 60 <td><img src="[% c.uri_for('/static', 'images', 'green-v.png') %]" 61 height="10px" width="[% res.count * 400 / vote.ballot_count_nonull(voteid) | format('%d') %]px"></td>61 height="10px" width="[% res.count * 400 / poll.ballot_count_nonull(voteid) | format('%d') %]px"></td> 62 62 </tr> 63 63 … … 71 71 </div> 72 72 73 [% FOREACH id = vote.list_vote_ballot(voteid)%]73 [% FOREACH id = poll.ballot_keys %] 74 74 [% IF loop.first %] 75 75 <div id="ballot_list" class="box"> … … 87 87 <td>[% id | html %]</td> 88 88 <td> 89 [% items = vote.ballot_items(id)%]89 [% items = poll.ballot(id).items %] 90 90 [% IF items.size %] 91 91 [% FOREACH item = items %] … … 101 101 </td> 102 102 <td> 103 [% invalid = '#' _ vote.ballot_info(id).invalid %]103 [% invalid = '#' _ poll.ballot(id).info.invalid %] 104 104 [% IF invalid == '#1' %] 105 105 <span class="alert">Invalidé</span>
Note: See TracChangeset
for help on using the changeset viewer.