diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-05 22:39:53 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-05 22:39:53 +0000 |
commit | 246c321617b18035725b3d42c6a313386687cedc (patch) | |
tree | 45262291e66caae786ed06873c2fe9e67089f8ae /lib/class | |
parent | ad3d2363c4c20d6b5049c8db92d08786650bd2ae (diff) | |
download | ampache-246c321617b18035725b3d42c6a313386687cedc.tar.gz ampache-246c321617b18035725b3d42c6a313386687cedc.tar.bz2 ampache-246c321617b18035725b3d42c6a313386687cedc.zip |
fixed some typos, minor bugs, updated the sql, added playlist as a browse type
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/playlist.class.php | 100 | ||||
-rw-r--r-- | lib/class/update.class.php | 58 |
2 files changed, 97 insertions, 61 deletions
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 = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id . '">' . $this->name . '</a>'; + $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title')); + $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id . '">' . $this->f_name . '</a>'; + + $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 */ diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 2af04264..2c5f5694 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -220,6 +220,13 @@ class Update { $version[] = array('version' => '340007','description' => $update_string); + $update_string = '- Modified Playlist_Data table to account for multiple object types.<br />' . + '- Verified previous updates, adjusting as needed.<br />' . + '- Dropped Allow Downsampling pref, configured in cfg file.<br />' . + '- Renamed Downsample Rate --> Transcode Rate to reflect new terminiology.<br />'; + + $version[] = array('version' => '340008','description' => $update_string); + return $version; } // populate_version @@ -309,7 +316,7 @@ class Update { * This updates the 'update_info' which is used by the updater * and plugins */ - private function set_version($key,$value) { + private static function set_version($key,$value) { $sql = "UPDATE update_info SET value='$value' WHERE `key`='$key'"; $db_results = Dba::query($sql); @@ -848,5 +855,54 @@ class Update { } // update_340007 + /** + * update_340008 + * This modifies the playlist table to handle the different types of objects that it needs to be able to + * store, and tweaks how dynamic playlist stuff works + */ + public static function update_340008() { + + $sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `playlist_data` CHANGE `dyn_song` `dynamic_song` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `playlist_data` ADD `object_type` VARCHAR( 32 ) NOT NULL DEFAULT 'song' AFTER `object_id`"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `playlist` ADD `genre` INT( 11 ) UNSIGNED NOT NULL AFTER `type`"; + $db_results = Dba::query($sql); + + $sql = "DELETE FROM `preference` WHERE `name`='allow_downsample_playback'"; + $db_results = Dba::query($sql); + + $sql = "UPDATE `preference` SET `description`='Transcode Bitrate' WHERE `name`='sample_rate'"; + $db_results = Dba::query($sql); + + // Check for old tables and drop if found, seems like there was a glitch that caused them + // not to get droped.. *shrug* + $sql = "DROP TABLE IF EXISTS `preferences`"; + $db_results = Dba::query($sql); + + $sql = "DROP TABLE IF EXISTS `song_ext_data`"; + $db_results = Dba::query($sql); + + $sql = "DROP TABLE IF EXISTS `ratings`"; + $db_results = Dba::query($sql); + + $sql = "SELECT `id` FROM `user`"; + $db_results = Dba::query($sql); + + User::fix_preferences('-1'); + + while ($r = Dba::fetch_assoc($db_results)) { + User::fix_preferences($r['id']); + } + + self::set_version('db_version','340008'); + + } // update_340008 + } // end update class ?> |