git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

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

Show a tag cloud of the user's top loved artists on their profile page

parent 0130a401
......@@ -74,7 +74,7 @@ class User {
$this->avatar_uri = $row['avatar_uri'];
$this->laconica_profile = $row['laconica_profile'];
$this->journal_rss = $row['journal_rss'];
$this->acctid = $this->getURL() . '#acct';
$THIS->acctid = $this->getURL() . '#acct';
$this->created = $row['created'];
$this->modified = $row['modified'];
$this->uniqueid = $row['uniqueid'];
......@@ -329,6 +329,40 @@ class User {
return $res;
}
/**
* Get a user's loved artists
*
* @param int $limit The number of artists to return (defaults to 10)
* @return An array of artist details
*/
function getLovedArtists($limit=10) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT artist, count(artist) as num FROM Loved_Tracks WHERE '
. ' userid = ' . $this->uniqueid . ' GROUP BY artist ORDER BY num DESC');
// Add meta data (url, tag size, etc.)
$i = 0;
$lovedWithMeta = array();
$sizes = array('xx-large', 'x-large', 'large', 'medium', 'small', 'x-small', 'xx-small');
foreach($res as $artist) {
$streamable = $adodb->cacheGetOne(86400, 'SELECT streamable FROM Artist WHERE name = ' . $adodb->qstr($artist['artist']));
if($streamable) {
$lovedWithMeta[$i]['artist'] = $artist['artist'];
$lovedWithMeta[$i]['numLoved'] = $artist['num'];
$lovedWithMeta[$i]['url'] = Server::getArtistURL($artist['artist']);
$lovedWithMeta[$i]['size'] = $sizes[(int) ($i/($limit/count($sizes)))];
$i++;
if($i >= $limit) {
break;
}
}
}
sort($lovedWithMeta);
return $lovedWithMeta;
}
/**
* Get a user's banned tracks
*
......
......@@ -53,6 +53,8 @@ if(isset($user->name)) {
if($user->hasLoved()) {
$recommendedArtists = $user->getRecommended(10);
$smarty->assign('recommendedArtists', $recommendedArtists);
$lovedArtists = $user->getLovedArtists(10);
$smarty->assign('lovedArtists', $lovedArtists);
}
$smarty->assign('isme', ($this_user->name == $user->name));
$smarty->assign('me', $user);
......
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