Got that first API call done
Had to work out the API parent class a bit. Also closing #8 as the API docs are about done. Time to knock out the rest of the API calls so I can start using this shit.
This commit is contained in:
parent
7b18541a61
commit
1006cbd436
5 changed files with 100 additions and 21 deletions
|
@ -2,9 +2,13 @@
|
|||
|
||||
class api_v1_leaderboards extends APIv1
|
||||
{
|
||||
protected $request_methods = 'GET';
|
||||
|
||||
public function __default()
|
||||
{
|
||||
|
||||
$leaderboards = new leaderboards();
|
||||
|
||||
return $leaderboards->__default();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,27 +6,37 @@ class leaderboards extends UserModule
|
|||
{
|
||||
// Grabs the user's leaderboards
|
||||
$leaderboards = $this->redis->zrevrange('user:' . $this->uid . ':leaderboards:updated', 0, -1, 'WITHSCORES');
|
||||
$data = array();
|
||||
|
||||
if ($leaderboards)
|
||||
{
|
||||
$this->redis->multi();
|
||||
|
||||
$leaderboard_uids = array();
|
||||
|
||||
// Grabs the additional fields
|
||||
foreach ($leaderboards as $uid => $updated_at)
|
||||
{
|
||||
$leaderboard_uids[] = $uid;
|
||||
unset($leaderboards[$uid]);
|
||||
$leaderboards[(int)$uid] = $updated_at;
|
||||
|
||||
$this->redis->hmget('leaderboard:' . $uid, array('name', 'created_at'));
|
||||
}
|
||||
|
||||
$data = array_combine($leaderboard_uids, $this->redis->exec());
|
||||
$fields = $this->redis->exec();
|
||||
|
||||
foreach ($leaderboards as $uid => $updated_at)
|
||||
{
|
||||
$data = current($fields);
|
||||
|
||||
$leaderboards[$uid] = array(
|
||||
'name' => $data['name'],
|
||||
'created_at' => (int)$data['created_at'],
|
||||
'updated_at' => (int)$updated_at,
|
||||
);
|
||||
|
||||
next($fields);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'leaderboards' => $leaderboards,
|
||||
'data' => $data,
|
||||
);
|
||||
return array('leaderboards' => $leaderboards);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue