Added some created at data and cleaned up some stuff
This commit is contained in:
parent
64a246838b
commit
706ebca0cf
5 changed files with 63 additions and 33 deletions
|
@ -12,7 +12,7 @@ class leaderboard_create extends leaderboard_new
|
||||||
|
|
||||||
public function __default()
|
public function __default()
|
||||||
{
|
{
|
||||||
// Checks the current UID value
|
// Grabs the next UID
|
||||||
$uid_key = 'leaderboard:uid';
|
$uid_key = 'leaderboard:uid';
|
||||||
|
|
||||||
if ($this->redis->get($uid_key) === false)
|
if ($this->redis->get($uid_key) === false)
|
||||||
|
@ -26,10 +26,15 @@ class leaderboard_create extends leaderboard_new
|
||||||
}
|
}
|
||||||
|
|
||||||
$timestamp = time();
|
$timestamp = time();
|
||||||
|
$record = array(
|
||||||
|
'name' => $_POST['name'],
|
||||||
|
'uid' => $this->uid,
|
||||||
|
'created_at' => $timestamp,
|
||||||
|
);
|
||||||
|
|
||||||
// Creates the rest of the data for the leaderboard
|
// Creates the rest of the data for the leaderboard
|
||||||
$this->redis->multi()
|
$this->redis->multi()
|
||||||
->hmset('leaderboard:' . $uid, array('name' => $_POST['name'], 'uid' => $this->uid))
|
->hmset('leaderboard:' . $uid, $record)
|
||||||
->zadd('user:' . $this->uid . ':leaderboards:updated', $timestamp, $uid)
|
->zadd('user:' . $this->uid . ':leaderboards:updated', $timestamp, $uid)
|
||||||
->zadd('leaderboards:updated', $timestamp, $uid)
|
->zadd('leaderboards:updated', $timestamp, $uid)
|
||||||
->exec();
|
->exec();
|
||||||
|
|
|
@ -6,7 +6,7 @@ class leaderboards extends UserModule
|
||||||
{
|
{
|
||||||
// Grabs the user's leaderboards
|
// Grabs the user's leaderboards
|
||||||
$leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES');
|
$leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES');
|
||||||
$names = array();
|
$data = array();
|
||||||
|
|
||||||
if ($leaderboards)
|
if ($leaderboards)
|
||||||
{
|
{
|
||||||
|
@ -17,15 +17,15 @@ class leaderboards extends UserModule
|
||||||
foreach ($leaderboards as $uid => $updated_at)
|
foreach ($leaderboards as $uid => $updated_at)
|
||||||
{
|
{
|
||||||
$leaderboard_uids[] = $uid;
|
$leaderboard_uids[] = $uid;
|
||||||
$this->redis->hget('leaderboard:' . $uid, 'name');
|
$this->redis->hmget('leaderboard:' . $uid, array('name', 'created_at'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = array_combine($leaderboard_uids, $this->redis->exec());
|
$data = array_combine($leaderboard_uids, $this->redis->exec());
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'leaderboards' => $leaderboards,
|
'leaderboards' => $leaderboards,
|
||||||
'names' => $names,
|
'data' => $data,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,17 @@ class user_create extends AnonymousModule
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grabs the next UID
|
// Grabs the next UID
|
||||||
$uid = $this->redis->incr('user:uid');
|
$uid_key = 'user:uid';
|
||||||
|
|
||||||
|
if ($this->redis->get($uid_key) === false)
|
||||||
|
{
|
||||||
|
$uid = 1000000;
|
||||||
|
$this->redis->set($uid_key, $uid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$uid = $this->redis->incr($uid_key);
|
||||||
|
}
|
||||||
|
|
||||||
// Generates the auth token
|
// Generates the auth token
|
||||||
$auth_token = sha1(microtime());
|
$auth_token = sha1(microtime());
|
||||||
|
@ -72,6 +82,7 @@ class user_create extends AnonymousModule
|
||||||
'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'),
|
'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'),
|
||||||
'auth' => $auth_token,
|
'auth' => $auth_token,
|
||||||
'api' => $api_key,
|
'api' => $api_key,
|
||||||
|
'created_at' => time(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$mapping_fields[] = 'user:api:' . $api_key;
|
$mapping_fields[] = 'user:api:' . $api_key;
|
||||||
|
|
|
@ -25,9 +25,9 @@ if ($this->module['api_key'])
|
||||||
|
|
||||||
<p class="lead">All <?php echo $site; ?> API calls start with <span class="label label-primary"><?php echo $url; ?>{version}</span> where <span class="label label-primary">{version}</span> corresponds to the version of the API you would like to use.</p>
|
<p class="lead">All <?php echo $site; ?> API calls start with <span class="label label-primary"><?php echo $url; ?>{version}</span> where <span class="label label-primary">{version}</span> corresponds to the version of the API you would like to use.</p>
|
||||||
|
|
||||||
<p class="lead">The current version of the <?php echo $site; ?> API is <span class="label label-primary">v1.0</span></p>
|
<p class="lead">The current version of the <?php echo $site; ?> API is <span class="label label-primary">v1</span></p>
|
||||||
|
|
||||||
<?php $url .= 'v1.0/'; ?>
|
<?php $url .= 'v1/'; ?>
|
||||||
|
|
||||||
<h2>Authentication</h2>
|
<h2>Authentication</h2>
|
||||||
|
|
||||||
|
|
|
@ -11,25 +11,39 @@
|
||||||
<?php
|
<?php
|
||||||
if ($this->module['leaderboards'])
|
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>';
|
<table class="table table-striped table-responsive">
|
||||||
|
<thead><tr>
|
||||||
|
<th>UID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last Activity</th>
|
||||||
|
<th></th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
foreach ($this->module['leaderboards'] as $uid => $updated_at)
|
foreach ($this->module['leaderboards'] as $uid => $updated_at)
|
||||||
{
|
{
|
||||||
|
$data = $this->module['data'][$uid];
|
||||||
?>
|
?>
|
||||||
<tr class="lead">
|
<tr class="lead">
|
||||||
<td><?php echo $uid; ?></td>
|
<td><?php echo $uid; ?></td>
|
||||||
<td><a href="/leaderboard/<?php echo $uid; ?>"><?php echo $this->module['names'][$uid]; ?></a></td>
|
<td><a href="/leaderboard/<?php echo $uid; ?>"><?php echo $data['name']; ?></a></td>
|
||||||
|
<td><?php echo Time::ago($data['created_at']); ?></td>
|
||||||
<td><?php echo Time::ago($updated_at); ?></td>
|
<td><?php echo Time::ago($updated_at); ?></td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
|
<div class="btn-group">
|
||||||
<a class="btn btn-danger" href="/leaderboard/delete/<?php echo $uid; ?>">Delete</a>
|
<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>
|
<a class="btn btn-primary" href="/leaderboard/edit/<?php echo $uid; ?>">Edit</a>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
echo '</tbody></table>';
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue