cvs: pearweb / package.php /include pear-voter.php /sql Makefile /templates election-showresults.tpl.php

From: Date: Tue, 21 Nov 2006 04:29:48 +0000
Subject: cvs: pearweb / package.php /include pear-voter.php /sql Makefile /templates election-showresults.tpl.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-5203@lists.php.net to get a copy of this message
cellog Tue Nov 21 04:29:48 2006 UTC Modified files: /pearweb/include pear-voter.php /pearweb package.php /pearweb/sql Makefile /pearweb/templates election-showresults.tpl.php Log: fix winner calculation in election interface add election tables to makefile http://cvs.php.net/viewvc.cgi/pearweb/include/pear-voter.php?r1=1.8&r2=1.9&diff_format=u Index: pearweb/include/pear-voter.php diff -u pearweb/include/pear-voter.php:1.8 pearweb/include/pear-voter.php:1.9 --- pearweb/include/pear-voter.php:1.8 Sat Nov 11 13:36:59 2006 +++ pearweb/include/pear-voter.php Tue Nov 21 04:29:47 2006 @@ -164,20 +164,49 @@ ', array($id), DB_FETCHMODE_ASSOC); $info['choices'] = $choices; $info['results'] = $this->dbh->getAll(' - SELECT e.votepercent, e.votetotal, c.summary, c.summary_link + SELECT e.votepercent, e.votetotal, c.choice, c.summary, c.summary_link FROM election_results e, election_choices c WHERE e.election_id = ? AND c.election_id = e.election_id AND c.choice = e.choice ORDER BY e.votetotal DESC ', array($id), DB_FETCHMODE_ASSOC); + + // calculate winners + $order = array(); + foreach ($info['results'] as $result) { + $order[$result['votetotal']][] = $result; + } + krsort($order, SORT_NUMERIC); + $winners = array(); + foreach ($order as $results) { + if (count($winners) >= $info['maximum_choices']) { + break; // done + } + foreach ($results as $result) { + $winners[] = $result['choice']; + } + } + $info['winners'] = $winners; + $abstain = $this->dbh->getOne(' SELECT COUNT(*) FROM election_votes_abstain WHERE election_id=? ', array($id)); - $wiki =& new Text_Wiki(); - $wiki->disableRule('wikilink'); - $info['detail'] = $wiki->transform($info['detail']); + $allvoters = $this->dbh->getOne(" + SELECT + COUNT(DISTINCT k.user) + FROM karma k, users u + WHERE + k.user = u.handle AND + k.level in ('pear.dev', 'pear.voter', 'pear.admin')", array()); + $votedthis = $this->dbh->getOne(' + SELECT count(*) FROM election_handle_votes where election_id=? + ', array($id)); + $info['turnout'] = $votedthis / $allvoters; + $wiki =& new Text_Wiki(); + $wiki->disableRule('wikilink'); + $info['detail'] = $wiki->transform($info['detail']); if ($info['maximum_choices'] > 1) { $total = $this->dbh->getOne(' SELECT COUNT(*) FROM election_votes_multiple WHERE http://cvs.php.net/viewvc.cgi/pearweb/package.php?r1=1.22&r2=1.23&diff_format=u Index: pearweb/package.php diff -u pearweb/package.php:1.22 pearweb/package.php:1.23 --- pearweb/package.php:1.22 Sat Nov 4 02:41:51 2006 +++ pearweb/package.php Tue Nov 21 04:29:48 2006 @@ -20,6 +20,7 @@ $a->setNotes(' * fix REST generation for deprecated packages/channels * fix REST generation of packagesinfo.xml for categories + * fix winner calculation in election interface * fix Bug #5340: User details are overescaped * fix Bug #8842: package.xml package name need not match case and must * fix Bug #9209: Missing package description in proposal editor http://cvs.php.net/viewvc.cgi/pearweb/sql/Makefile?r1=1.33&r2=1.34&diff_format=u Index: pearweb/sql/Makefile diff -u pearweb/sql/Makefile:1.33 pearweb/sql/Makefile:1.34 --- pearweb/sql/Makefile:1.33 Sat Oct 21 00:03:40 2006 +++ pearweb/sql/Makefile Tue Nov 21 04:29:48 2006 @@ -32,6 +32,7 @@ users.sql \ pepr.sql \ apidoc_queue.sql \ + election.sql \ karma.sql SQL_TYPE=mysql SQL_USER=pear http://cvs.php.net/viewvc.cgi/pearweb/templates/election-showresults.tpl.php?r1=1.5&r2=1.6&diff_format=u Index: pearweb/templates/election-showresults.tpl.php diff -u pearweb/templates/election-showresults.tpl.php:1.5 pearweb/templates/election-showresults.tpl.php:1.6 --- pearweb/templates/election-showresults.tpl.php:1.5 Thu Nov 9 05:10:18 2006 +++ pearweb/templates/election-showresults.tpl.php Tue Nov 21 04:29:48 2006 @@ -16,15 +16,17 @@ $info['voteend']; ?></td> </tr> <tr> - <th class="form-label_left">Results (<?php echo $info['maximum_choices'] ?> winners)</th> + <th class="form-label_left">Voter turnout</th> + <td class="form-input"><?php echo number_format($info['turnout'] * 100, 2) ?>%</td> + </tr> + <tr> + <th class="form-label_left">Results (<?php echo count($info['winners']) ?> winners)</th> <td class="form-input"> <table> <tr><th>Vote percentage</th><th>Choice</th><th>Votes</th></td></tr> <?php - $winners = array(); foreach ($info['results'] as $i => $result) { - $winners[$result['votetotal']] = 1; - if (count($winners) <= $info['maximum_choices']) { + if (in_array($result['choice'], $info['winners'])) { echo '<tr><td class="vote-winner">' . number_format($result['votepercent'] * 100, 2) . '%</td><td class="vote-winner"><a href="' . $result['summary_link'] . '">' . htmlspecialchars($result['summary']) .

« previous php.pear.core (#5203) next »