Adding donors page to About dropdown

Lists all donors, their donation setting and total donated amount.
This will allow people to see who is contributing to the pool.

Fixes #223
This commit is contained in:
Sebastian Grewe 2013-06-23 20:12:34 +02:00
parent ff4cc88872
commit 2e7a4a8092
4 changed files with 72 additions and 2 deletions

View File

@ -9,11 +9,12 @@ class Transaction {
private $table = 'transactions';
private $tableBlocks = 'blocks';
public function __construct($debug, $mysqli, $config, $block) {
public function __construct($debug, $mysqli, $config, $block, $user) {
$this->debug = $debug;
$this->mysqli = $mysqli;
$this->config = $config;
$this->block = $block;
$this->user = $user;
$this->debug->append("Instantiated Transaction class", 2);
}
@ -116,6 +117,36 @@ class Transaction {
return true;
}
/**
* Get all donation transactions
* Used on donors page
* return data array Donors and amounts
**/
public function getDonations() {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("
SELECT
SUM(t.amount) AS donation,
a.username AS username,
a.donate_percent AS donate_percent
FROM $this->table AS t
LEFT JOIN " . $this->user->getTableName() . " AS a
ON t.account_id = a.id
LEFT JOIN blocks AS b
ON t.block_id = b.id
WHERE
(
( t.type = 'Donation' AND b.confirmations >= " . $this->config['confirmations'] . " ) OR
t.type = 'Donation_PPS'
)
GROUP BY a.username
");
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
$this->debug->append("Failed to fetch website donors: " . $this->mysqli->error);
return false;
}
/**
* Get total balance for all users locked in wallet
* This includes any outstanding unconfirmed transactions!
@ -231,4 +262,4 @@ class Transaction {
}
}
$transaction = new Transaction($debug, $mysqli, $config, $block);
$transaction = new Transaction($debug, $mysqli, $config, $block, $user);

View File

@ -0,0 +1,11 @@
<?php
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
$aDonors = $transaction->getDonations();
// Tempalte specifics
$smarty->assign("DONORS", $aDonors);
$smarty->assign("CONTENT", "default.tpl");
?>

View File

@ -0,0 +1,27 @@
{include file="global/block_header.tpl" BLOCK_HEADER="Pool Donors"}
<center>
{include file="global/pagination.tpl"}
<table width="500px" class="pagesort">
<thead>
<tr>
<th>Name</th>
<th class="center">%</th>
<th class="right">{$GLOBAL.config.currency} Total</th>
</tr>
</thead>
<tbody>
{section name=donor loop=$DONORS}
<tr>
<td>{$DONORS[donor].username}</td>
<td class="center">{$DONORS[donor].donate_percent}</td>
<td class="right">{$DONORS[donor].donation|number_format:"2"}</td>
</tr>
{sectionelse}
<tr>
<td class="center" colspan="3">No donors yet! Be the first one to donate!</td>
</tr>
{/section}
</tbody>
</table>
</center>
{include file="global/block_footer.tpl"}

View File

@ -31,6 +31,7 @@
<li><a href="{$smarty.server.PHP_SELF}?page=about&action=pool">About</a>
<ul>
<li><a href="{$smarty.server.PHP_SELF}?page=about&action=pool">This Pool</a></li>
<li><a href="{$smarty.server.PHP_SELF}?page=about&action=donors">Pool Donors</a></li>
</ul>
</li>
{if $smarty.session.AUTHENTICATED|default == 1}<li><a href="{$smarty.server.PHP_SELF}?page=logout">Logout</a></li>{else}<li><a href="{$smarty.server.PHP_SELF}?page=register">Register</a></li>{/if}