diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-10-15 20:08:53 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-10-15 20:08:53 +0000 |
commit | 3d6a49a218c6d4faf51d486602bd7d9e88c98264 (patch) | |
tree | c99aeb3a0cd64b0e58ab1cc2c6ede79c06ec1bda /lib/class/tmp_playlist.class.php | |
parent | f4bf617e40d00d2670fe2b21b61de5e17473ed4b (diff) | |
download | ampache-3d6a49a218c6d4faf51d486602bd7d9e88c98264.tar.gz ampache-3d6a49a218c6d4faf51d486602bd7d9e88c98264.tar.bz2 ampache-3d6a49a218c6d4faf51d486602bd7d9e88c98264.zip |
fixed some zip file issues quarantine migration issues and added a bunch to the tmp playlist class
Diffstat (limited to 'lib/class/tmp_playlist.class.php')
-rw-r--r-- | lib/class/tmp_playlist.class.php | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/class/tmp_playlist.class.php b/lib/class/tmp_playlist.class.php index 7c29c235..2bf4cd4a 100644 --- a/lib/class/tmp_playlist.class.php +++ b/lib/class/tmp_playlist.class.php @@ -78,4 +78,137 @@ class tmpPlaylist { } // _get_info + /** + * get_items + * This returns an array of all object_ids currently in this tmpPlaylist + */ + function get_items() { + + $sql = "SELECT object_id FROM tmp_playlist_data " . + "WHERE tmp_playlist_data.tmp_playlist='" . sql_escape($this->id) . "'"; + $db_results = mysql_query($sql, dbh()); + + while ($results = mysql_fetch_assoc($db_results)) { + $items[] = $results['id']; + } + + return $items; + + } // get_items + + /** + * ceate + * This function initializes a new tmpPlaylist it is assoicated with the current + * session rather then a user, as you could have same user multiple locations + */ + function create($sessid,$type,$object_type,$base_playlist) { + + $sessid = sql_escape($sessid); + $type = sql_escape($type); + $object_type = sql_escape($object_type); + $base_playlist = sql_escape($base_playlist); + + $sql = "INSERT INTO tmp_playlist (`session`,`type`,`object_type`,`base_playlist`) " . + " VALUES ('$sessid','$type','$object_type','$base_playlist')"; + $db_results = mysql_query($sql, dbh()); + + $id = mysql_insert_id(dbh()); + + return $id; + + } // create + + /** + * 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' + * by this user, naturally it checks to make sure that the user hasn't + * already voted on any of these objects + */ + function vote($items) { + + /* Itterate through the objects if no vote, add to playlist and vote */ + foreach ($items as $object_id) { + if (!$this->has_vote($object_id)) { + $this->add_vote($object_id); + } + } // end foreach + + + } // vote + + /** + * add_vote + * This takes a object id and user and actually inserts the row + */ + function add_vote($object_id) { + + $object_id = sql_escape($object_id); + + /* If it's on the playlist just vote */ + $sql = "SELECT id FROM tmp_playlist_data " . + "WHERE tmp_playlist_data.object_id='$object_id'"; + $db_results = mysql_query($sql, dbh()); + + /* If it's not there, add it and pull ID */ + if (!$results = mysql_fetch_assoc($db_results)) { + $sql = "INSERT INTO tmp_playlist_data (`tmp_playlist`,`object_id`) " . + "VALUES ('-1','$object_id')"; + $db_results = mysql_query($sql, dbh()); + $results['id'] = mysql_insert_id(dbh()); + } + + /* Vote! */ + $sql = "INSERT INTO user_vote (`user`,`object_id`) " . + "VALUES ('" . sql_escape($GLOBALS['user']->id) . "','" . $results['id'] . "')"; + $db_results = mysql_query($sql, dbh()); + + return true; + + } // add_vote + + /** + * has_vote + * This checks to see if the current user has already voted on this object + */ + function has_vote($object_id) { + + /* Query vote table */ + $sql = "SELECT tmp_playlist_data.id FROM user_vote " . + "INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " . + "WHERE user_vote.user='" . sql_escape($GLOBALS['user']->id) . "' " . + " AND tmp_playlist_data.object_id='" . sql_escape($object_id) . "' " . + " AND tmp_playlist_data.tmp_playlist='-1'"; + $db_results = mysql_query($sql, dbh()); + + /* If we find row, they've voted!! */ + if (mysql_num_rows($db_results)) { + return false; + } + + return true; + + } // has_vote + + /** + * delete_track + * This deletes a track and any assoicated votes, we only check for + * votes if it's a -1 session + */ + 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()); + } + + /* delete the track its self */ + $sql = "DELETE FROM tmp_playlist_data WHERE id='$id'"; + $db_results = mysql_query($sql,dbh()); + + } // delete_track + } // class tmpPlaylist |