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

Commit 2f6a4866 authored by Mike Sheldon's avatar Mike Sheldon

Implement user.getTopTags() web service method

parent 413a01af
......@@ -74,6 +74,7 @@ $method_map = array(
'user.getinfo' => method_user_getinfo,
'user.gettoptracks' => method_user_gettoptracks,
'user.getrecenttracks' => method_user_getrecenttracks,
'user.gettoptags' => method_user_gettoptags,
'radio.tune' => method_radio_tune,
'radio.getplaylist' => method_radio_getPlaylist,
'track.gettoptags' => method_track_getTopTags,
......@@ -89,6 +90,16 @@ function method_user_getrecenttracks() {
print(XML::prettyXML(UserXML::getRecentTracks($_GET['user'], $_GET['limit'])));
}
function method_user_gettoptags() {
if (!isset($_GET['user'])) {
report_failure(LFM_INVALID_SIGNATURE);
}
header('Content-Type: text/xml');
print(XML::prettyXML(UserXML::getTopTags($_GET['user'])));
}
function method_user_gettoptracks() {
if (!isset($_GET['user'])) {
report_failure(LFM_INVALID_SIGNATURE);
......
......@@ -138,5 +138,30 @@ class UserXML {
return($xml);
}
public static function getTopTags($u, $limit=10) {
global $base_url;
try {
$user = new User($u);
$res = $user->getTopTags($limit);
} catch (exception $ex) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('toptags');
$root->addAttribute('user', $user->name);
foreach($res as &$row) {
$tag = $root->addChild('tag', null);
$tag->addChild('name', repamp($row['tag']));
$tag->addChild('count', repamp($row['freq']));
$tag->addChild('url', repamp($base_url . '/tag/' . $row['tag']));
}
return $xml;
}
}
?>
......@@ -285,4 +285,21 @@ class User {
return $tracks;
}
/**
* Get a user's most used tags
*
* @param int $limit The number of tags to return (default to 10)
* @return An array of tag details
*/
function getTopTags($limit=10) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT tag, COUNT(tag) AS freq FROM tags WHERE '
. ' userid = ' . $this->uniqueid
. ' GROUP BY tag '
. ' LIMIT ' . $limit);
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