diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-24 21:48:22 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-24 21:48:22 +0000 |
commit | 6e299a7f63b5b5f056667dee6788fe4c5626be5f (patch) | |
tree | a4e9b70bd393d7dc260b32b347aaec74f2da9409 /lib/class | |
parent | 27ba8110cab5b09220a110f0e2f3af026582c9fc (diff) | |
download | ampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.tar.gz ampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.tar.bz2 ampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.zip |
fixed voting up/down and removal of songs from democratic playlist after playback
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/democratic.class.php | 38 | ||||
-rw-r--r-- | lib/class/stream.class.php | 4 | ||||
-rw-r--r-- | lib/class/tmpplaylist.class.php | 31 |
3 files changed, 34 insertions, 39 deletions
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index 0944dcae..aa908a65 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -157,6 +157,26 @@ class Democratic extends tmpPlaylist { } // get_next_object /** + * get_uid_from_object_id + * This takes an object_id and an object type and returns the ID for the row + */ + public function get_uid_from_object_id($object_id,$object_type='') { + + $object_id = Dba::escape($object_id); + $object_type = $object_type ? Dba::escape($object_type) : 'song'; + $tmp_id = Dba::escape($this->id); + + $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " . + "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'"; + $db_results = Dba::query($sql); + + $row = Dba::fetch_assoc($db_results); + + return $row['id']; + + } // get_uid_from_object_id + + /** * vote * This function is called by users to vote on a system wide playlist * This adds the specified objects to the tmp_playlist and adds a 'vote' @@ -167,8 +187,10 @@ class Democratic extends tmpPlaylist { /* Itterate through the objects if no vote, add to playlist and vote */ foreach ($items as $type=>$object_id) { + //FIXME: This is a hack until we fix everything else + if (intval($type)) { $type = 'song'; } if (!$this->has_vote($object_id,$type)) { - $this->add_vote($object_id,$this->id,$type); + $this->add_vote($object_id,$type); } } // end foreach @@ -186,7 +208,7 @@ class Democratic extends tmpPlaylist { $user_id = Dba::escape($GLOBALS['user']->id); /* Query vote table */ - $sql = "SELECT tmp_playlist_data.id FROM `user_vote` " . + $sql = "SELECT tmp_playlist_data.object_id FROM `user_vote` " . "INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . "WHERE user_vote.user='$user_id' AND tmp_playlist_data.object_type='$type' " . "AND tmp_playlist_data.object_id='$object_id' " . @@ -206,10 +228,10 @@ class Democratic extends tmpPlaylist { * add_vote * This takes a object id and user and actually inserts the row */ - public function add_vote($object_id,$tmp_playlist,$object_type='') { + public function add_vote($object_id,$object_type='') { $object_id = Dba::escape($object_id); - $tmp_playlist = Dba::escape($tmp_playlist); + $tmp_playlist = Dba::escape($this->id); $object_type = $object_type ? Dba::escape($object_type) : 'song'; /* If it's on the playlist just vote */ @@ -241,14 +263,12 @@ class Democratic extends tmpPlaylist { * 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) { + public function remove_vote($row_id) { - $object_id = Dba::escape($object_id); + $object_id = Dba::escape($row_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) . "'"; + $sql = "DELETE FROM `user_vote` WHERE `object_id`='$object_id'"; $db_results = Dba::query($sql); /* Clean up anything that has no votes */ diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 9aa1f76a..09f3cf8a 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -471,8 +471,8 @@ class Stream { */ public function create_democratic() { - $tmp_playlist = Democratic::get_current_playlist(); - $tmp_playlist->vote($this->songs); + $democratic = Democratic::get_current_playlist(); + $democratic->vote($this->songs); } // create_democratic diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php index 781067dd..9e0c5a3a 100644 --- a/lib/class/tmpplaylist.class.php +++ b/lib/class/tmpplaylist.class.php @@ -130,8 +130,8 @@ class tmpPlaylist { $order = 'ORDER BY id ASC'; /* Select all objects from this playlist */ - $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " . - "FROM tmp_playlist_data $vote_join " . + $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id " . + "FROM tmp_playlist_data " . "WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order"; $db_results = Dba::query($sql); @@ -158,37 +158,12 @@ class tmpPlaylist { $tmp_id = Dba::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 = ", 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 " . + $sql = "SELECT tmp_playlist_data.object_id FROM tmp_playlist_data " . "WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1"; $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 ($this->type == 'vote' AND !$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 |