From 8e9678729653489a0839c14bc23d743e1509c319 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 30 Jul 2007 06:21:50 +0000 Subject: added your playlists with play link to the leftbar, no way to edit them yet --- lib/class/playlist.class.php | 90 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 40 deletions(-) (limited to 'lib/class/playlist.class.php') diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index a5a6fd75..f5f570ec 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -1,13 +1,13 @@ id = intval($playlist_id); + $this->id = intval($id); $info = $this->_get_info(); - $this->name = $info['name']; - $this->user = $info['user']; - $this->type = $info['type']; - $this->date = $info['date']; + + foreach ($info as $key=>$value) { + $this->$key = $value; + } } // Playlist @@ -59,17 +56,28 @@ class Playlist { * This is an internal (private) function that gathers the information for this object from the * playlist_id that was passed in. */ - function _get_info() { + private function _get_info() { - $sql = "SELECT * FROM `playlist` WHERE `id`='" . sql_escape($this->id) . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT * FROM `playlist` WHERE `id`='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results; } // _get_info + /** + * format + * This takes the current playlist object and gussies it up a little + * bit so it is presentable to the users + */ + public function format() { + + $this->f_link = '' . $this->name . ''; + + } // format + /** * get_track * Takes a playlist_data.id and returns the current track value for said entry @@ -90,16 +98,16 @@ class Playlist { * This returns an array of playlist songs that are in this playlist. Because the same * song can be on the same playlist twice they are key'd by the uid from playlist_data */ - function get_items() { - - $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "' ORDER BY track"; - $db_results = mysql_query($sql, dbh()); + public function get_items() { - while ($r = mysql_fetch_assoc($db_results)) { + $results = array(); - $key = $r['id']; - $results[$key] = $r; + $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; + $db_results = Dba::query($sql); + while ($row = Dba::fetch_assoc($db_results)) { + $key = $row['id']; + $results[$key] = $row['song']; } // end while return $results; @@ -225,23 +233,25 @@ class Playlist { } // get_song_count /** - * has_access - * This takes no arguments. It looks at the currently logged in user (_SESSION) - * This accounts for admin powers and the access on a per list basis + * get_users + * This returns the specified users playlists as an array of + * playlist ids */ - function has_access() { + public static function get_users($user_id) { - // Admin always have rights - if ($GLOBALS['user']->has_access(100)) { return true; } + $user_id = Dba::escape($user_id); + $results = array(); - // People under 25 don't get playlist access even if they created it - if (!$GLOBALS['user']->has_access(25)) { return false; } + $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id'"; + $db_results = Dba::query($sql); - if ($this->user == $GLOBALS['user']->id) { return true; } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return false; + return $results; - } // has_access + } // get_users /** * update_type -- cgit