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

Commit f60e9030 authored by Mike Sheldon's avatar Mike Sheldon

Merge branch 'master' of gitorious.org:~Elleo/foocorp/elleos-gnu-fm

parents 78a3a27b 9dcdf61d
......@@ -110,13 +110,10 @@ function method_user_getRecentTracks() {
report_failure(LFM_INVALID_PARAMS);
}
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
}
$limit = get_with_default('limit', 50);
$page = get_with_default('page', 1);
$xml = UserXML::getRecentTracks($_GET['user'], $_GET['limit'], $page);
$xml = UserXML::getRecentTracks($_GET['user'], $limit, $page);
respond($xml);
}
......@@ -154,13 +151,11 @@ function method_user_getLovedTracks() {
}
$user = $_GET['user'];
if (isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit = 50;
}
$xml = UserXML::getLovedTracks($user, $limit);
$limit = get_with_default('limit', 50);
$page = get_with_default('page', 1);
$xml = UserXML::getLovedTracks($user, $limit, $page);
respond($xml);
}
......@@ -170,13 +165,10 @@ function method_user_getBannedTracks() {
}
$user = $_GET['user'];
if (isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit = 50;
}
$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);
}
......@@ -186,11 +178,7 @@ function method_user_getNeighbours() {
}
$user = $_GET['user'];
if (isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit = 50;
}
$limit = get_with_default('limit', 50);
$xml = UserXML::getNeighbours($user, $limit);
respond($xml);
......@@ -585,6 +573,14 @@ function json_response($data) {
}
}
function get_with_default($param, $default) {
if (isset($_GET[$param])) {
return $_GET[$param];
} else {
return $default;
}
}
$_REQUEST['method'] = strtolower($_REQUEST['method']);
if (!isset($_REQUEST['method']) || !isset($method_map[$_REQUEST['method']]))
report_failure(LFM_INVALID_METHOD);
......
......@@ -188,18 +188,26 @@ class UserXML {
return $xml;
}
public static function getLovedTracks($u, $limit=50) {
public static function getLovedTracks($u, $limit=50, $page=1) {
global $adodb;
$offset = ($page - 1) * $limit;
try {
$user = new User($u);
$res = $user->getLovedTracks($limit);
$res = $user->getLovedTracks($limit, $offset);
} catch (exception $ex) {
return XML::error('error', '7', 'Invalid resource specified');
}
$totalPages = $adodb->GetOne('SELECT COUNT(track) FROM Loved_Tracks WHERE userid = ' . $user->uniqueid);
$totalPages = ceil($totalPages / $limit);
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('lovedtracks');
$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);
......@@ -209,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);
......
......@@ -339,12 +339,12 @@ class User {
* @param int $limit The number of tracks to return (defaults to 50)
* @return array An array of track details
*/
function getLovedTracks($limit=50) {
function getLovedTracks($limit=50, $offset=0) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT * FROM Loved_Tracks WHERE '
. ' userid = ' . $this->uniqueid . ' ORDER BY time DESC'
. ' LIMIT ' . $limit);
. ' LIMIT ' . $limit . ' OFFSET ' . $offset);
return $res;
}
......@@ -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