"My Leaderboards" page

This commit is contained in:
Josh Sherman 2013-12-17 13:44:49 -05:00
parent beea5e57c1
commit fa408978fd
3 changed files with 41 additions and 3 deletions

View file

@ -25,7 +25,7 @@ class leaderboard_create extends leaderboard_new
$uid = $this->redis->incr($uid_key);
}
$timestamp = Time::timestamp();
$timestamp = time();
// Creates the rest of the data for the leaderboard
$this->redis->multi()

View file

@ -5,9 +5,28 @@ class leaderboards extends UserModule
public function __default()
{
// Grabs the user's leaderboards
$leaderboards = array();
$leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES');
$names = array();
return array('leaderboards' => $leaderboards);
if ($leaderboards)
{
$this->redis->multi();
$leaderboard_uids = array();
foreach ($leaderboards as $uid => $updated_at)
{
$leaderboard_uids[] = $uid;
$this->redis->hget('leaderboard:' . $uid, 'name');
}
$names = array_combine($leaderboard_uids, $this->redis->exec());
}
return array(
'leaderboards' => $leaderboards,
'names' => $names,
);
}
}

View file

@ -3,6 +3,7 @@
<h1>My Leaderboards</h1>
</div>
<div class="col-xs-12 col-sm-6 text-right">
<br>
<a class="btn btn-success" href="/leaderboard/new">New Leaderboard</a>
</div>
</div>
@ -10,7 +11,25 @@
<?php
if ($this->module['leaderboards'])
{
echo '<table class="table table-striped table-responsive">';
echo '<thead><tr><th>UID</th><th>Name</th><th>Last Activity</th><th></th></tr></thead><tbody>';
foreach ($this->module['leaderboards'] as $uid => $updated_at)
{
?>
<tr class="lead">
<td><?php echo $uid; ?></td>
<td><?php echo $this->module['names'][$uid]; ?></td>
<td><?php echo Time::ago($updated_at); ?></td>
<td class="text-right">
<a class="btn btn-danger" href="/leaderboard/delete/<?php echo $uid; ?>">Delete</a>
<a class="btn btn-primary" href="/leaderboard/edit/<?php echo $uid; ?>">Edit</a>
</td>
</tr>
<?php
}
echo '</tbody></table>';
}
else
{