diff --git a/nixtape/data/PlayStats.php b/nixtape/data/PlayStats.php index 152f003f753841123d3228513f8ed2a18ed67bcb..64b488a25d65e2a6b9e359a1e918c804ec8b6a86 100644 --- a/nixtape/data/PlayStats.php +++ b/nixtape/data/PlayStats.php @@ -38,8 +38,7 @@ class PlayStats { if (!is_string($field)) return false; if (!is_string($table)) return false; if (!is_integer($limit)) return false; - $sizes = array('xx-large', 'x-large', 'large', 'medium', 'small', 'x-small', 'xx-small'); - $query = "SELECT $field, count(*) AS count FROM $table"; + $query = "SELECT $field, count(*) AS count FROM $table"; $query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE ' : null; if ($field == "track") { $query .= (!is_null($constraint)) ? ' artist = ' . $mdb2->quote($constraint, 'text') : null; @@ -68,5 +67,39 @@ class PlayStats { return $data; } } + + static function generatePlayByDays($table, $limit = 100, $constraint = null, $maxwidth = 100 ) { + global $mdb2; + if (!is_string($table)) return false; + if (!is_integer($limit)) return false; + $query = "SELECT COUNT(*) as count,DATE(FROM_UNIXTIME(time)) as date FROM $table"; + $query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE ' : null; + $query .= (!is_null($constraint)) ? ' username = ' . $mdb2->quote($constraint, 'text') : null; + $query .= (!is_null($constraint) && ($table == "Scrobbles")) ? ' AND ' : null; + $query .= ($table == "Scrobbles") ? " rating <> 'S' " : null; + $query .= " GROUP BY date ORDER BY date DESC LIMIT $limit"; + $res = $mdb2->query($query); + if (PEAR::isError($res)) { + echo("ERROR" . $res->getMessage()); + } + + if (!$res->numRows()) { + return false; + } else { + $data = $res->fetchAll(MDB2_FETCHMODE_ASSOC); + + $max = 0; + + foreach($data as &$i){ + if( $i['count'] > $max ) $max = $i['count']; + } + + foreach($data as &$i){ + $i['size'] = $i['count'] / $max * $maxwidth; + } + + return $data; + } + } } ?> diff --git a/nixtape/stats.php b/nixtape/stats.php index bb2f9885b824499c5443ccd6ef66110e6c5ef18e..67dff8f7fa66cb2d7b46119855a89014c9c2de0f 100644 --- a/nixtape/stats.php +++ b/nixtape/stats.php @@ -56,12 +56,17 @@ if(isset($user->name)) { $smarty->assign('user_tagcloud',$aUserTagCloud); } - $smarty->assign('stat_barwidth', 300); + $smarty->assign('stat_barwidth', 320); $aUserPlayStat = PlayStats::GeneratePlayStats('Scrobbles', 'artist', 40, $user->name, 300); if (!PEAR::isError ($aUserPlayStat)) { $smarty->assign('user_playstats',$aUserPlayStat); } + $aUserDayStat = PlayStats::generatePlayByDays('Scrobbles', 40, $user->name, 300); + if (!PEAR::isError ($aUserDayStat)) { + $smarty->assign('user_daystats',$aUserDayStat); + } + $smarty->assign('isme', ($_SESSION['user']->name == $user->name)); $smarty->assign('stats', true); diff --git a/nixtape/themes/librefm/templates/stats.tpl b/nixtape/themes/librefm/templates/stats.tpl index bb045117535e416a3cc1d3e357ba05156719625e..d7d0b14ff7326a60aa8cf7ded0dca2842932dffe 100644 --- a/nixtape/themes/librefm/templates/stats.tpl +++ b/nixtape/themes/librefm/templates/stats.tpl @@ -43,7 +43,14 @@ {section name=i loop=$user_playstats}
{$user_daystats[i].count} | {$user_daystats[i].date} |