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

Commit 5f04b7f3 authored by tonyb486's avatar tonyb486

Experimental tag cloud for user

parent ccaf6b72
......@@ -86,6 +86,26 @@ class User {
return Server::getUserURL($this->name);
}
/**
* Get a user's top artists
*
* @return An array of artists for the top 10 artists
* with a percent field, which represents each
* artist in comparison to the most popular.
*/
function getTagCloud() {
global $mdb2;
$res = $mdb2->query(" SELECT artist, count(artist) AS count FROM Scrobbles WHERE "
. 'username = ' . $mdb2->quote($this->name, 'text')
. " GROUP BY artist ORDER BY count DESC LIMIT 10");
$data= $res->fetchAll(MDB2_FETCHMODE_ASSOC);
foreach($data as &$i) {
$i['percent'] = 6-(int)(($i['count']/$data[0]['count'])*5);
}
return $data;
}
/**
* Get a user's now-playing tracks
*
......
......@@ -42,6 +42,8 @@ if(isset($user->name)) {
$smarty->assign('userlevel', $user->userlevel);
$smarty->assign('avatar', $user->getAvatar());
$smarty->assign('nowplaying', $user->getNowPlaying(10));
$smarty->assign('tagcloud', $user->getTagCloud());
$smarty->assign('profile', true);
$smarty->display('profile.tpl');
} else {
$smarty->assign('error', 'User not found');
......
</div></div>
{if !$profile}
<div class="yui-u" id="sidebar">
<div style="padding: 10px;">
<h3>Explore popular artists</h3>
<ul class="tagcloud">
<li class="tc t1"><a href="#">They Might Be Giants</a></li>
<li class="tc t3"><a href="#">John Lennon</a></li>
......@@ -24,10 +24,9 @@
<li class="tc t1"><a href="#">Solar Fields</a></li>
<li class="tc t4"><a href="#">billy talent</a></li>
<li class="tc t3"><a href="#">Blur</a></li>
</ul>
</ul>
</div></div>
{/if}
</div></div>
<div class="yui-g" id="artists">
......@@ -63,4 +62,4 @@ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sit amet metu
</div>
</div>
</body>
</html>
\ No newline at end of file
</html>
......@@ -46,6 +46,13 @@
{capture name=artist_last}{$scrobbles[i].artist}{/capture}
{/section}
</dl>
</div></div>
<div class="yui-u" id="sidebar">
<div style="padding: 10px;">
<h3>User's favorite artists</h3>
<ul class="tagcloud">
{section name=i loop=$tagcloud}
<li class="tc t{$tagcloud[i].percent}"><a href="#">{$tagcloud[i].artist}</a></li>
{/section}
</ul>
{include file='footer.tpl'}
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