From 2faea5f7b345ba0d9319d4466261b52c7bff0325 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 23 Oct 2006 01:47:18 +0000 Subject: re-wroked stats which means major db update, some stats dealies may still not work correctly --- lib/general.lib.php | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'lib/general.lib.php') diff --git a/lib/general.lib.php b/lib/general.lib.php index f933ef94..d9823a40 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -535,13 +535,14 @@ function get_random_songs( $options, $matchlist) { $artists_where = ltrim($artists_where," OR"); $query = "SELECT song.id,song.size FROM song WHERE $artists_where ORDER BY RAND()"; } - elseif ($options['random_type'] == 'unplayed') { - $uid = $GLOBALS['user']->id; - $query = "SELECT song.id,song.size FROM song LEFT JOIN object_count ON song.id = object_count.object_id " . - "WHERE ($where) AND ((object_count.object_type='song' AND userid = '$uid') OR object_count.count IS NULL ) " . - "ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " . - "ELSE RAND()*object_count.count END " . $options['limit']; - } // If unplayed +/* TEMP DISABLE */ +// elseif ($options['random_type'] == 'unplayed') { +// $uid = $GLOBALS['user']->id; +// $query = "SELECT song.id,song.size FROM song LEFT JOIN object_count ON song.id = object_count.object_id " . +// "WHERE ($where) AND ((object_count.object_type='song' AND user = '$uid') OR object_count.count IS NULL ) " . +// "ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " . +// "ELSE RAND()*object_count.count END " . $options['limit']; +// } // If unplayed else { $query = "SELECT id,size FROM song WHERE $where ORDER BY RAND() " . $options['limit']; } @@ -606,47 +607,44 @@ function cleanup_and_exit($playing_id) { */ function get_global_popular($type) { - /* Select out the most popular based on object_count */ - $sql = "SELECT object_id, SUM(count) as count FROM object_count" . - " WHERE object_type = '$type'" . - " GROUP BY object_id" . - " ORDER BY count DESC LIMIT " . conf('popular_threshold'); - $db_result = mysql_query($sql,dbh()); - - $items = array(); + $stats = new Stats(); + $count = conf('popular_threshold'); $web_path = conf('web_path'); - - while ( $r = @mysql_fetch_object($db_result) ) { + + /* Pull the top */ + $results = $stats->get_top($count,$type); + + foreach ($results as $r) { /* If Songs */ if ( $type == 'song' ) { - $song = new Song($r->object_id); + $song = new Song($r['object_id']); $artist = $song->get_artist_name(); $text = "$artist - $song->title"; /* Add to array */ $items[] = "
  • id\" title=\"". scrub_out($text) ."\">" . - scrub_out(truncate_with_ellipse($text, conf('ellipse_threshold_title')+3)) . " ($r->count)
  • "; + scrub_out(truncate_with_ellipse($text, conf('ellipse_threshold_title')+3)) . " (" . $r['count'] . ") "; } // if it's a song /* If Artist */ elseif ( $type == 'artist' ) { - $artist = get_artist_name($r->object_id); + $artist = get_artist_name($r['object_id']); $items[] = "
  • object_id\" title=\"". scrub_out($artist) ."\">" . - scrub_out(truncate_with_ellipse($artist, conf('ellipse_threshold_artist')+3)) . " ($r->count)
  • "; + scrub_out(truncate_with_ellipse($artist, conf('ellipse_threshold_artist')+3)) . " (" . $r['count'] . ") "; } // if type isn't artist /* If Album */ elseif ( $type == 'album' ) { - $album = new Album($r->object_id); + $album = new Album($r['object_id']); $items[] = "
  • object_id\" title=\"". scrub_out($album->name) ."\">" . - scrub_out(truncate_with_ellipse($album->name,conf('ellipse_threshold_album')+3)) . " ($r->count)
  • "; + scrub_out(truncate_with_ellipse($album->name,conf('ellipse_threshold_album')+3)) . " (" . $r['count'] . ") "; } // else not album elseif ($type == 'genre') { - $genre = new Genre($r->object_id); + $genre = new Genre($r['object_id']); $items[] = "
  • object_id\" title=\"" . scrub_out($genre->name) . "\">" . - scrub_out(truncate_with_ellipse($genre->name,conf('ellipse_threshold_title')+3)) . " ($r->count)
  • "; + scrub_out(truncate_with_ellipse($genre->name,conf('ellipse_threshold_title')+3)) . " (" . $r['count'] . ") "; } // end if genre - } // end while + } // end foreach if (count($items) == 0) { $items[] = "
  • " . _('Not Enough Data') . "
  • \n"; -- cgit