From 311ac991126f68b12a6a29747091544de4acf6a1 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 10 Mar 2008 05:24:59 +0000 Subject: minor fixes to the playlist, fixed up the democratic playlist kinda, still does not work completely --- democratic.php | 15 ++++++++++++++- docs/CHANGELOG | 1 + lib/class/api.class.php | 13 ++++++++++++- lib/class/catalog.class.php | 6 ++++-- lib/class/democratic.class.php | 30 ++++++++++++++++++++++++++++-- lib/class/update.class.php | 14 ++++++++++++++ server/democratic.ajax.php | 2 +- stream.php | 2 +- templates/show_manage_democratic.inc.php | 5 +++-- 9 files changed, 78 insertions(+), 10 deletions(-) diff --git a/democratic.php b/democratic.php index 6cca46c4..ec7c7fcc 100644 --- a/democratic.php +++ b/democratic.php @@ -1,7 +1,7 @@ $token,'api'=>self::$version,'update'=>date("r",$row['update']),'add'=>date("r",$row['add'])); + // Now we need to quickly get the totals of songs + $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`,COUNT(DISTINCT(`artist`)) AS `artist` FROM `song`"; + $db_results = Dba::query($sql); + $counts = Dba::fetch_assoc($db_results); + + return array('auth'=>$token, + 'api'=>self::$version, + 'update'=>date("r",$row['update']), + 'add'=>date("r",$row['add']), + 'songs'=>$counts['song'], + 'albums'=>$counts['album'], + 'artists'=>$counts['artist']); } // match } // end while diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 0b152458..02e780e8 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1582,11 +1582,13 @@ class Catalog { public static function clean_playlists() { /* Do a complex delete to get playlist songs where there are no songs */ - $sql = "DELETE FROM playlist_data USING playlist_data LEFT JOIN song ON song.id = playlist_data.song WHERE song.file IS NULL"; + $sql = "DELETE FROM `playlist_data` USING `playlist_data` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` " . + "WHERE `song`.`file` IS NULL AND `playlist_data`.`object_type`='song'"; $db_results = Dba::query($sql); // Clear TMP Playlist information as well - $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data LEFT JOIN song ON tmp_playlist_data.object_id = song.id WHERE song.id IS NULL"; + $sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` LEFT JOIN `song` ON `tmp_playlist_data`.`object_id` = `song`.`id` " . + "WHERE `song`.`id` IS NULL"; $db_results = Dba::query($sql); } // clean_playlists diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index 32ecbee2..922120d2 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -373,6 +373,32 @@ class Democratic extends tmpPlaylist { } // delete_votes + /** + * delete + * This deletes a democratic playlist + */ + public static function delete($democratic_id) { + + $democratic_id = Dba::escape($democratic_id); + + $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'"; + $db_results = Dba::query($sql); + + return true; + + } // delete + + /** + * update + * This updates an existing democratic playlist item. It takes a key'd array just like the create + */ + public function update($data) { + + + + + } // update + /** * create * This is the democratic play create function it inserts this into the democratic table @@ -387,8 +413,8 @@ class Democratic extends tmpPlaylist { $default = Dba::escape($data['make_default']); $user = Dba::escape($GLOBALS['user']->id); - $sql = "INSERT INTO `democratic` (`name`,`cooldown`,`level`,`user`,`primary`) " . - "VALUES ('$name','$cool','$level','$user','$default')"; + $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " . + "VALUES ('$name','$base','$cool','$level','$user','$default')"; $db_results = Dba::query($sql); return $db_results; diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 924e87e7..42cd9b86 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1158,5 +1158,19 @@ class Update { } // update_340016 + /** + * update_340017 + * This finalizes the democratic table. + */ + public static function update_340017() { + + $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`"; + $db_results = Dba::query($sql); + + self::set_version('db_version','340017'); + + + } // update_340017 + } // end update class ?> diff --git a/server/democratic.ajax.php b/server/democratic.ajax.php index 123bd3c5..e7bd745b 100644 --- a/server/democratic.ajax.php +++ b/server/democratic.ajax.php @@ -68,7 +68,7 @@ switch ($_REQUEST['action']) { exit; } - $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=democratic'; + $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=democratic&democratic_id=' . scrub_out($_REQUEST['democratic_id']); $results['rfc3514'] = ''; break; default: diff --git a/stream.php b/stream.php index dd66a579..ac93e9bb 100644 --- a/stream.php +++ b/stream.php @@ -144,7 +144,7 @@ switch ($_REQUEST['action']) { $song_ids = get_random_songs($options, $matchlist); break; case 'democratic': - $democratic = Democratic::get_current_playlist(); + $democratic = new Democratic($_REQUEST['democratic_id']); $urls[] = $democratic->get_url(); $song_ids = array('0'); break; diff --git a/templates/show_manage_democratic.inc.php b/templates/show_manage_democratic.inc.php index 8361e525..8498bebc 100644 --- a/templates/show_manage_democratic.inc.php +++ b/templates/show_manage_democratic.inc.php @@ -1,7 +1,7 @@ f_primary; ?> count_items(); ?> - + id,'all',_('Play'),'play_democratic'); ?> + -- cgit