diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-24 21:16:13 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-24 21:16:13 +0000 |
commit | 27ba8110cab5b09220a110f0e2f3af026582c9fc (patch) | |
tree | d54b665062b1dab40deff47ca519eca1ee251db0 /lib | |
parent | 3508380e994d80c6df1a287606a969c218d81694 (diff) | |
download | ampache-27ba8110cab5b09220a110f0e2f3af026582c9fc.tar.gz ampache-27ba8110cab5b09220a110f0e2f3af026582c9fc.tar.bz2 ampache-27ba8110cab5b09220a110f0e2f3af026582c9fc.zip |
democratic play working, if still slightly sketchy
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/democratic.class.php | 100 | ||||
-rw-r--r-- | lib/class/tmpplaylist.class.php | 49 |
2 files changed, 100 insertions, 49 deletions
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index 78bf5fde..0944dcae 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -79,8 +79,8 @@ class Democratic extends tmpPlaylist { public function get_items() { $order = "GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; - $vote_select = ", COUNT(user_vote.user) AS `count`"; - $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; + $vote_select = ", COUNT(user_vote.user) AS `count`"; + $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id"; /* Select all objects from this playlist */ $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " . @@ -99,6 +99,62 @@ class Democratic extends tmpPlaylist { } // get_items + /** + * get_url + * This returns the special play URL for democratic play, only open to ADMINs + */ + public function get_url() { + + $link = Config::get('web_path') . '/play/index.php?demo_id=' . scrub_out($this->id) . + '&sid=' . Stream::get_session() . '&uid=' . scrub_out($GLOBALS['user']->id); + return $link; + + } // get_url + + /** + * 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 + */ + public function get_next_object($offset='') { + + $tmp_id = Dba::escape($this->id); + + // Format the limit statement + $limit_sql = $offset ? intval($offset) . ',1' : '1'; + + /* Add conditions for voting */ + $vote_select = ", COUNT(user_vote.user) AS `count`"; + $order = " GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC"; + $vote_join = "INNER 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 $limit_sql"; + $db_results = Dba::query($sql); + + $results = Dba::fetch_assoc($db_results); + + /* If nothing was found and this is a voting playlist then get from base_playlist */ + if (!$results) { + + /* Check for a playlist */ + if ($this->base_playlist != '0') { + /* 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['0']; + } + else { + $sql = "SELECT `id` as `object_id` FROM `song` WHERE `enabled`='1' ORDER BY RAND() LIMIT 1"; + $db_results = Dba::query($sql); + $results = Dba::fetch_assoc($db_results); + } + } + + return $results['object_id']; + + } // get_next_object /** * vote @@ -179,6 +235,46 @@ class Democratic extends tmpPlaylist { } // add_vote + /** + * remove_vote + * This is called to remove a vote by a user for an object, it uses the object_id + * As that's what we'll have most the time, no need to check if they've got an existing + * vote for this, just remove anything that is there + */ + public function remove_vote($object_id) { + + $object_id = Dba::escape($object_id); + $user_id = Dba::escape($GLOBALS['user']->id); + + $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . + "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . + "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); + + /* Clean up anything that has no votes */ + self::prune_tracks(); + + return true; + + } // remove_vote + + /** + * delete_votes + * This removes the votes for the specified object on the current playlist + */ + public function delete_votes($row_id) { + + $row_id = Dba::escape($row_id); + + $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'"; + $db_results = Dba::query($sql); + + $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'"; + $db_results = Dba::query($sql); + + return true; + + } // delete_votes } // Democratic class diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php index 1ab3ea39..781067dd 100644 --- a/lib/class/tmpplaylist.class.php +++ b/lib/class/tmpplaylist.class.php @@ -194,19 +194,6 @@ class tmpPlaylist { } // get_next_object /** - * get_vote_url - * This returns the special play URL for democratic play, only open to ADMINs - */ - public function get_vote_url() { - - $link = Config::get('web_path') . '/play/index.php?tmp_id=' . scrub_out($this->id) . - '&sid=' . scrub_out(session_id()) . '&uid=' . scrub_out($GLOBALS['user']->id); - - return $link; - - } // get_vote_url - - /** * count_items * This returns a count of the total number of tracks that are in this tmp playlist */ @@ -392,32 +379,8 @@ class tmpPlaylist { } // vote_active /** - * remove_vote - * This is called to remove a vote by a user for an object, it uses the object_id - * As that's what we'll have most the time, no need to check if they've got an existing - * vote for this, just remove anything that is there - */ - public function remove_vote($object_id) { - - $object_id = Dba::escape($object_id); - $user_id = Dba::escape($GLOBALS['user']->id); - - $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . - "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " . - "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'"; - $db_results = Dba::query($sql); - - /* Clean up anything that has no votes */ - self::prune_tracks(); - - return true; - - } // remove_vote - - /** * delete_track - * This deletes a track and any assoicated votes, we only check for - * votes if it's vote playlist, id is a object_id + * This deletes a track from the tmpplaylist */ public function delete_track($id) { @@ -428,18 +391,10 @@ class tmpPlaylist { " WHERE `id`='$id'"; $db_results = Dba::query($sql); - /* 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 = Dba::query($sql); - } - return true; } // delete_track - + /** * clear_playlist * This is really just a wrapper function, it clears the entire playlist |