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

Commit fdf89499 authored by Daniel Watkins's avatar Daniel Watkins

Move Top. Artist. determination stuff into data/Server.php, and use...

Move Top. Artist. determination stuff into data/Server.php, and use standardised URLs on explore page.
parent ad5c6c39
......@@ -62,6 +62,31 @@ class Server {
return $result;
}
/**
* Retrieves a list of popular artists
*
* @param int $number The number of artists to return
* @return An array of artists or a PEAR_Error in case of failure
*/
static function getTopArtists($number=20) {
global $mdb2;
$res = $mdb2->query("SELECT COUNT(artist) as c, artist FROM Scrobbles GROUP BY artist ORDER BY c DESC LIMIT 0,20");
if(PEAR::isError($res)) {
return $res;
}
$data = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
foreach($data as $i) {
$row = sanitize($i);
$row["artisturl"] = Server::getArtistURL($row["artist"]);
$result[] = $row;
}
return $result;
}
/**
* Retrieves a list of the currently playing tracks
*
......
......@@ -22,14 +22,9 @@
require_once("database.php");
require_once("templating.php");
require_once("data/Server.php");
$res = $mdb2->query("SELECT COUNT(artist) as c, artist FROM Scrobbles GROUP BY artist ORDER BY c DESC LIMIT 0,20");
if(PEAR::isError($res)) {
die($res->getMessage());
}
$smarty->assign("topartists", $res->fetchAll(MDB2_FETCHMODE_ASSOC));
$smarty->assign("topartists", Server::getTopArtists(20));
$smarty->assign("explore", true);
$smarty->display("explore-artists.tpl");
......
......@@ -6,7 +6,7 @@
{section name=popular loop=$topartists}
<li>
<dl>
<dt><a href="artist.php?artist={$topartists[popular].artist|stripslashes|urlencode}">
<dt><a href="{$topartists[popular].artisturl}">
{$topartists[popular].artist|stripslashes}</a></dt>
<dd>{$topartists[popular].c} gobbles</dd>
</dl>
......
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