From 246c321617b18035725b3d42c6a313386687cedc Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 5 Aug 2007 22:39:53 +0000 Subject: fixed some typos, minor bugs, updated the sql, added playlist as a browse type --- lib/class/playlist.class.php | 100 +++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 60 deletions(-) (limited to 'lib/class/playlist.class.php') diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index 863a28a5..493e335a 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -30,6 +30,7 @@ class Playlist { public $name; public $user; public $type; + public $genre; public $date; /* Generated Elements */ @@ -74,7 +75,12 @@ class Playlist { */ public function format() { - $this->f_link = '' . $this->name . ''; + $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title')); + $this->f_link = '' . $this->f_name . ''; + + $client = new User($this->user); + + $this->f_user = $client->fullname; } // format @@ -102,12 +108,16 @@ class Playlist { $results = array(); - $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; + $sql = "SELECT `object_id`,`object_type`,`dynamic_song` 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']; + + if (strlen($row['dynamic_song'])) { + // Do something here FIXME! + } + + $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']); } // end while return $results; @@ -115,85 +125,56 @@ class Playlist { } // get_items /** - * get_songs - * This returns an array of song_ids accounting for any dyn_song entries this playlist - * may have. This is what should be called when trying to generate a m3u or other playlist + * get_random_items + * This is the same as before but we randomize the buggers! */ - function get_songs($array=array()) { - - $results = array(); - - /* If we've passed in some songs */ - if (count($array)) { - - foreach ($array as $data) { - - $sql = "SELECT song,dyn_song FROM playlist_data WHERE id='" . sql_escape($data) . "' ORDER BY track"; - $db_results = mysql_query($sql, dbh()); + public function get_random_items() { - $r = mysql_fetch_assoc($db_results); - if ($r['dyn_song']) { - $array = $this->get_dyn_songs($r['dyn_song']); - $results = array_merge($array,$results); - } - else { - $results[] = $r['song']; - } - - } // end foreach songs - - return $results; + $results = array(); - } // end if we were passed some data + $sql = "SELECT `object_id`,`object_type`,`dynamic_song` FROM `playlist_data` " . + "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND()"; + $db_results = Dba::query($sql); - $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "' ORDER BY track"; - $db_results = mysql_query($sql, dbh()); + while ($row = Dba::fetch_assoc($db_results)) { - while ($r = mysql_fetch_assoc($db_results)) { - if ($r['dyn_song']) { - $array = $this->get_dyn_songs($r['dyn_song']); - $results = array_merge($array,$results); - } - else { - $results[] = $r['song']; + if (strlen($row['dynamic_song'])) { + // Do something here FIXME!!! } - } // end while + $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']); + } // end while - return $results; + return $results; - } // get_songs + } // get_random_items /** - * get_random_songs - * This returns all of the songs in a random order, except those - * pulled from dyn_songs, takes an optional limit + * get_songs + * This is called by the batch script, because we can't pass in Dynamic objects they pulled once and then their + * target song.id is pushed into the array */ - 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() $limit_sql"; - $db_results = mysql_query($sql, dbh()); + function get_songs() { $results = array(); - while ($r = mysql_fetch_assoc($db_results)) { + $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; + $db_results = Dba::query($sql); + + while ($r = Dba::fetch_assoc($db_results)) { if ($r['dyn_song']) { $array = $this->get_dyn_songs($r['dyn_song']); $results = array_merge($array,$results); } else { - $results[] = $r['song']; - } + $results[] = $r['object_id']; + } + } // end while return $results; - } // get_random_songs + } // get_songs /** * get_dyn_songs @@ -298,7 +279,6 @@ class Playlist { /** * update_track_numbers - * This function takes an array of $array['song_id'] $array['track'] where song_id is really the * playlist_data.id and updates them */ -- cgit