cvs: pearweb /cron election_results.php /include pear-voter.php /sql election.sql /templates election-showresults.tpl.php
| From: | Greg Beaver | Date: | Thu, 09 Nov 2006 04:05:32 +0000 |
| Subject: | cvs: pearweb /cron election_results.php /include pear-voter.php /sql election.sql /templates election-showresults.tpl.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-5161@lists.php.net to get a copy of this message | ||
cellog Thu Nov 9 04:05:32 2006 UTC
Modified files:
/pearweb/cron election_results.php
/pearweb/include pear-voter.php
/pearweb/sql election.sql
/pearweb/templates election-showresults.tpl.php
Log:
show vote totals as well as percentage, re-format election
results page
http://cvs.php.net/viewvc.cgi/pearweb/cron/election_results.php?r1=1.1&r2=1.2&diff_format=u
Index: pearweb/cron/election_results.php
diff -u pearweb/cron/election_results.php:1.1 pearweb/cron/election_results.php:1.2
--- pearweb/cron/election_results.php:1.1 Mon Nov 6 05:54:53 2006
+++ pearweb/cron/election_results.php Thu Nov 9 04:05:31 2006
@@ -51,9 +51,10 @@
foreach ($results as $vote) {
$dbh->query('
INSERT INTO election_results
- (election_id, choice, votepercent)
- VALUES(?,?,?)
- ', array($election['id'], $vote['vote'],
$vote['total'] / $totalvotes));
+ (election_id, choice, votepercent, votetotal)
+ VALUES(?,?,?,?)
+ ', array($election['id'], $vote['vote'],
$vote['total'] / $totalvotes,
+ $vote['total']));
}
}
}
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/pearweb/include/pear-voter.php?r1=1.3&r2=1.4&diff_format=u
Index: pearweb/include/pear-voter.php
diff -u pearweb/include/pear-voter.php:1.3 pearweb/include/pear-voter.php:1.4
--- pearweb/include/pear-voter.php:1.3 Tue Nov 7 05:47:05 2006
+++ pearweb/include/pear-voter.php Thu Nov 9 04:05:31 2006
@@ -160,12 +160,12 @@
', array($id), DB_FETCHMODE_ASSOC);
$info['choices'] = $choices;
$info['results'] = $this->dbh->getAll('
- SELECT e.votepercent, c.summary, c.summary_link
+ SELECT e.votepercent, e.votetotal, 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.votepercent DESC
+ ORDER BY e.votetotal DESC
', array($id), DB_FETCHMODE_ASSOC);
$abstain = $this->dbh->getOne('
SELECT COUNT(*) FROM election_votes_abstain
@@ -188,8 +188,10 @@
// percentage of abstaining voters
if ($total + $abstain > 0) {
$info['abstain'] = $abstain / ($total + $abstain);
+ $info['abstaincount'] = $abstain;
} else {
$info['abstain'] = 0;
+ $info['abstaincount'] = 0;
}
return $info;
}
http://cvs.php.net/viewvc.cgi/pearweb/sql/election.sql?r1=1.2&r2=1.3&diff_format=u
Index: pearweb/sql/election.sql
diff -u pearweb/sql/election.sql:1.2 pearweb/sql/election.sql:1.3
--- pearweb/sql/election.sql:1.2 Mon Nov 6 05:54:53 2006
+++ pearweb/sql/election.sql Thu Nov 9 04:05:31 2006
@@ -56,5 +56,6 @@
election_id INT NOT NULL,
choice TINYINT NOT NULL,
votepercent FLOAT NOT NULL,
+ votetotal BIGINT NOT NULL,
PRIMARY KEY (election_id, choice)
);
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/pearweb/templates/election-showresults.tpl.php?r1=1.3&r2=1.4&diff_format=u
Index: pearweb/templates/election-showresults.tpl.php
diff -u pearweb/templates/election-showresults.tpl.php:1.3
pearweb/templates/election-showresults.tpl.php:1.4
--- pearweb/templates/election-showresults.tpl.php:1.3 Tue Nov 7 05:47:06 2006
+++ pearweb/templates/election-showresults.tpl.php Thu Nov 9 04:05:31 2006
@@ -11,28 +11,30 @@
$info['voteend']; ?></td>
</tr>
<tr>
- <th class="form-label_left">Results</th>
+ <th class="form-label_left">Results (<?php echo
$info['maximum_choices'] ?> winners)</th>
<td class="form-input">
<table>
- <tr><td class="vote-winner">Winners</td><td
class="vote-winner"><?php echo $info['maximum_choices']
?></td></tr>
+ <tr><th>Vote
percentage</th><th>Choice</th><th>Votes</th></td></tr>
<?php
$winners = array();
foreach ($info['results'] as $i => $result) {
- $winners[number_format($result['votepercent'] * 100, 2)] = 1;
+ $winners[$result['votetotal']] = 1;
if (count($winners) <= $info['maximum_choices']) {
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']) .
- '</a></td></tr>';
+ '</a></td><td class="vote-winner">' .
number_format($result['votetotal']) .
+ '</td></tr>';
} else {
echo '<tr><td>' . number_format($result['votepercent'] *
100, 2) .
'%</td><td><a href="' .
$result['summary_link'] . '">' .
htmlspecialchars($result['summary']) .
- '</a></td></tr>';
+ '</a></td><td>' .
number_format($result['votetotal']) .
+ '</td></tr>';
}
}
?>
- <tr><td><?php echo number_format($info['abstain'] * 100, 2)
?>%</td><td>Abstained</td></tr>
+ <tr><td><?php echo number_format($info['abstain'] * 100, 2)
?>%</td><td>Abstained</td><td><?php echo
number_format($info['abstaincount']) ?></td></tr>
</table>
</td>
</tr>