diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-05 09:59:50 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-05 09:59:50 +0000 |
commit | d3b5f2f3f814f0342094b60614af10ec7b9d82b2 (patch) | |
tree | 261b00384b64dffec1274735db9fe564bd4e67dc | |
parent | 99ed8eb9b0bb7f80bb12201c5231fe97c67cf452 (diff) | |
download | ampache-d3b5f2f3f814f0342094b60614af10ec7b9d82b2.tar.gz ampache-d3b5f2f3f814f0342094b60614af10ec7b9d82b2.tar.bz2 ampache-d3b5f2f3f814f0342094b60614af10ec7b9d82b2.zip |
more work towards the democratic play stuff, really need a UI to test from here on out
-rw-r--r-- | lib/class/playlist.class.php | 10 | ||||
-rw-r--r-- | lib/class/tmp_playlist.class.php | 67 | ||||
-rw-r--r-- | play/index.php | 23 |
3 files changed, 82 insertions, 18 deletions
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index 866e8ba8..af4962c9 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -159,12 +159,16 @@ class Playlist { /** * get_random_songs * This returns all of the songs in a random order, except those - * pulled from dyn_songs + * pulled from dyn_songs, takes an optional limit */ - function get_random_songs() { + function get_random_songs($limit='') { + + if ($limit) { + $limit_sql = "LIMIT " . intval($limit); + } $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'" . - " ORDER BY RAND()"; + " ORDER BY RAND() $limit_sql"; $db_results = mysql_query($sql, dbh()); $results = array(); diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmp_playlist.class.php index 2a85be2f..e730f09f 100644 --- a/lib/class/tmp_playlist.class.php +++ b/lib/class/tmp_playlist.class.php @@ -5,9 +5,8 @@ All rights reserved. This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License v2 + as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -96,6 +95,43 @@ class tmpPlaylist { } // get_items + /** + * get_next_object + * This returns the next object in the tmp_playlist most of the time this + * will just be the top entry, but if there is a base_playlist and no + * items in the playlist then it returns a random entry from the base_playlist + */ + function get_next_object() { + + $tmp_id = sql_escape($this->id); + $order = " ORDER BY tmp_playlist_data.id DESC"; + + /* Check for an item on the playlist, account for voting */ + if ($this->type == 'vote') { + /* Add conditions for voting */ + $vote_select = ", user_vote.user AS `count`"; + $order = " ORDER BY `counte` DESC"; + $vote_join = "LEFT JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + } + + $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " . + "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1"; + $db_resutls = mysql_query($sql, dbh()); + + $results = mysql_fetch_assoc($db_results); + + /* If nothing was found and this is a voting playlist then get from base_playlist */ + if ($this->type == 'vote' AND !$results) { + /* We need to pull a random one from the base_playlist */ + $base_playlist = new playlist($this->base_playlist); + $data = $base_playlist->get_random_songs(1); + $results['object_id'] = $data['song']; + } + + return $results['object_id']; + + } // get_next_object + /** * create * This function initializes a new tmpPlaylist it is assoicated with the current @@ -260,22 +296,29 @@ class tmpPlaylist { /** * delete_track * This deletes a track and any assoicated votes, we only check for - * votes if it's a -1 session + * votes if it's vote playlist, id is a object_id */ function delete_track($id) { - $id = sql_escape($id); - - /* If this is a -1 session then kill votes as well */ - if ($this->session = '-1') { - $sql = "DELETE FROM user_vote WHERE object_id='$id'"; - $db_results = mysql_query($sql, dbh()); - } + $id = sql_escape($id); + $tmp_id = sql_escape($this->id); /* delete the track its self */ - $sql = "DELETE FROM tmp_playlist_data WHERE id='$id'"; + $sql = "DELETE FROM tmp_playlist_data " . + " WHERE tmp_playlist='$tmp_id' AND object_id='$id'"; $db_results = mysql_query($sql,dbh()); + /* If this is a voting playlit prune votes */ + if ($this->type == 'vote') { + $sql = "DELETE FROM user_vote USING user_vote " . + "LEFT JOIN tmp_playlist_data ON user_vote.object_id = tmp_playlist_data.id " . + "WHERE tmp_playlist_data.id IS NULL"; + $db_results = mysql_query($sql,dbh()); + } + + return true; + } // delete_track + } // class tmpPlaylist diff --git a/play/index.php b/play/index.php index dde92d05..89be25b8 100644 --- a/play/index.php +++ b/play/index.php @@ -5,9 +5,8 @@ All rights reserved. This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License v2 + as published by the Free Software Foundation This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -37,6 +36,9 @@ $uid = scrub_in($_REQUEST['uid']); $song_id = scrub_in($_REQUEST['song']); $sid = scrub_in($_REQUEST['sid']); +/* This is specifically for tmp playlist requests */ +$tmp_id = scrub_in($_REQUEST['tmp_id']); + /* First things first, if we don't have a uid stop here */ if (!isset($uid)) { debug_event('no_song',"Error: No Song UID Specified, nothing to play",'2'); @@ -81,7 +83,18 @@ if (conf('access_control')) { } } // access_control is enabled +/** + * If we've got a tmp playlist then get the + * current song, and do any other crazyness + * we need to + */ +if ($tmp_playlist = new tmpPlaylist($tmp_id)) { + /* This takes into account votes etc and removes the */ + $song_id = $tmp_playlist->get_next_object(); +} + +/* Base Checks passed create the song object */ $song = new Song($song_id); $song->format_song(); $catalog = new Catalog($song->catalog); @@ -242,6 +255,10 @@ while (!feof($fp) && (connection_status() == 0)) { if ($bytesStreamed > $minBytesStreamed) { $user->update_stats($song_id); + /* If this is a voting tmp playlist remove the entry */ + if ($tmp_playlist->type == 'vote') { + $tmp_playlist->delete_track($song_id); + } } /* Set the Song as Played if it isn't already */ |