We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 8fb13205 authored by Mike Sheldon's avatar Mike Sheldon

Add pagination to user.getBannedTracks webservice method

parent 9b60c972
......@@ -166,8 +166,9 @@ function method_user_getBannedTracks() {
$user = $_GET['user'];
$limit = get_with_default('limit', 50);
$page = get_with_default('page', 1);
$xml = UserXML::getBannedTracks($user, $limit);
$xml = UserXML::getBannedTracks($user, $limit, $page);
respond($xml);
}
......
......@@ -217,18 +217,26 @@ class UserXML {
return $xml;
}
public static function getBannedTracks($u, $limit=50) {
public static function getBannedTracks($u, $limit=50, $page=1) {
global $adodb;
$offset = ($page - 1) * $limit;
try {
$user = new User($u);
$res = $user->getBannedTracks($limit);
$res = $user->getBannedTracks($limit, $offset);
} catch (exception $ex) {
return XML::error('error', '7', 'Invalid resource specified');
}
$totalPages = $adodb->GetOne('SELECT COUNT(track) FROM Banned_Tracks WHERE userid = ' . $user->uniqueid);
$totalPages = ceil($totalPages / $limit);
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('bannedtracks');
$root->addAttribute('user', $user->name);
$root->addAttribute('page', $page);
$root->addAttribute('perPage', $limit);
$root->addAttribute('totalPages', $totalPages);
foreach($res as &$row) {
$track_node = $root->addChild('track', null);
......
......@@ -389,12 +389,12 @@ class User {
* @param int $limit The number of tracks to return (defaults to 50)
* @return array An array of track details
*/
function getBannedTracks($limit=50) {
function getBannedTracks($limit=50, $offset=0) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT * FROM Banned_Tracks WHERE '
. ' userid = ' . $this->uniqueid . ' ORDER BY time DESC'
. ' LIMIT ' . $limit);
. ' LIMIT ' . $limit . ' OFFSET ' . $offset);
return $res;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment