diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-24 05:02:50 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-24 05:02:50 +0000 |
commit | d7f75d16b5ef190eb0bad3c7e9fcbd1e248c5a41 (patch) | |
tree | 4eb95868731f087a78a1da1cf92abf31ac48bc0c | |
parent | a74d0b7163c8755e23598997c364bc75a18f943e (diff) | |
download | ampache-d7f75d16b5ef190eb0bad3c7e9fcbd1e248c5a41.tar.gz ampache-d7f75d16b5ef190eb0bad3c7e9fcbd1e248c5a41.tar.bz2 ampache-d7f75d16b5ef190eb0bad3c7e9fcbd1e248c5a41.zip |
added album and artist dynamic options, tweaked display and how you add em... still not happy with it, but good enough for now
-rw-r--r-- | lib/class/random.class.php | 85 | ||||
-rw-r--r-- | lib/preferences.php | 2 | ||||
-rw-r--r-- | server/ajax.server.php | 3 | ||||
-rw-r--r-- | templates/rightbar.inc.php | 25 | ||||
-rw-r--r-- | themes/classic/templates/default.css | 5 |
5 files changed, 105 insertions, 15 deletions
diff --git a/lib/class/random.class.php b/lib/class/random.class.php index 0a72fdf6..a5ce5a1a 100644 --- a/lib/class/random.class.php +++ b/lib/class/random.class.php @@ -141,22 +141,95 @@ class Random { } // get_genre /** + * get_album + * This looks at the last album played by the current user and + * picks something else in the same album + */ + public static function get_album($limit) { + + $results = array(); + + // Get the last album playbed by us + $data = $GLOBALS['user']->get_recently_played('1','album'); + if ($data['0']) { + $where_sql = " WHERE `album`='" . $data['0'] . "' "; + } + + $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + return $results; + + } // get_album + + /** + * get_artist + * This looks at the last artist played and then randomly picks a song from the + * same artist + */ + public static function get_artist($limit) { + + $results = array(); + + $data = $GLOBALS['user']->get_recently_player('1','artist'); + if ($data['0']) { + $where_sql = " WHERE `artist`='" . $data['0'] . "' "; + } + + $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_resutls)) { + $results[] = $row['id']; + } + + return $results; + + } // get_artist + + /** + * get_type_name + * This returns a 'purrty' name for the differnt random types + */ + public static function get_type_name($type) { + + switch ($type) { + case 'album': + return _('Related Album'); + break; + case 'genre': + return _('Related Genre'); + break; + case 'artist': + return _('Related Artist'); + break; + default: + return _('Pure Random'); + break; + } // end switch + + } // get_type_name + + /** * validiate_type - * this validates the random type, this is a private function + * this validates the random type */ - private static function validate_type($type) { + public static function validate_type($type) { switch ($type) { - case 'special': - $type = $GLOBALS['user']->prefs['random_method']; - break; + case 'default': case 'genre': case 'album': case 'artist': case 'rated': + return $type; break; default: - return false; + return 'default'; break; } // end switch diff --git a/lib/preferences.php b/lib/preferences.php index b54d8cf7..18b88057 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -325,7 +325,7 @@ function create_preference_input($name,$value) { break; case 'random_method': echo "<select name=\"$name\">\n"; - echo "\t<option value=\"default\">" . _('Default') . "</option>"; + echo "\t<option value=\"default\">" . _('Pure Random') . "</option>"; echo "\t<option value=\"album\">" . _('Related Album') . "</option>"; echo "\t<option value=\"genre\">" . _('Related Genre') . "</option>"; echo "</select>\n"; diff --git a/server/ajax.server.php b/server/ajax.server.php index 28736115..8681e720 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -194,7 +194,8 @@ switch ($action) { } break; case 'dynamic': - $GLOBALS['user']->playlist->add_object('0','special'); + $random_type = Random::validate_type($_REQUEST['random_type']); + $GLOBALS['user']->playlist->add_object('0',$random_type); break; default: case 'song': diff --git a/templates/rightbar.inc.php b/templates/rightbar.inc.php index 6dbdabe0..73104e3c 100644 --- a/templates/rightbar.inc.php +++ b/templates/rightbar.inc.php @@ -30,9 +30,6 @@ </li> <?php } ?> <li> - <?php echo Ajax::button('?action=basket&type=dynamic','cog',_('Add Dynamic Item'),'rightbar_dynamic_playlist'); ?> - </li> - <li> <?php echo Ajax::button('?action=basket&type=clear_all','delete',_('Clear Playlist'),'rightbar_clear_playlist'); ?> </li> </ul> @@ -42,13 +39,13 @@ //FIXME :: this feels kludgy $objects = $GLOBALS['user']->playlist->get_items(); foreach ($objects as $uid=>$object_data) { - if ($object_data['1'] == 'special') { - $object->f_link = _('Dynamic Playlist Item'); - } - else { + if ($object_data['1'] == 'radio' || $object_data['1'] == 'song') { $object = new $object_data['1']($object_data['0']); $object->format(); } + else { + $object->f_link = Random::get_type_name($object_data['1']); + } ?> <tr class="<?php echo flip_class(); ?>"> <td> @@ -63,4 +60,18 @@ <?php } ?> </table> </div> +<div id="rightbar-bottom"> +<h4><?php echo _('Add Dynamic Items'); ?></h4> +<span><?php echo Ajax::button('?action=basket&type=dynamic&random_type=default','add',_('Add'),'rightbar_pure_random'); ?> +<?php echo _('Pure Random'); ?></span> + +<span><?php echo Ajax::button('?action=basket&type=dynamic&random_type=artist','add',_('Add'),'rightbar_related_artist'); ?> +<?php echo _('Related Artist'); ?></span> + +<span><?php echo Ajax::button('?action=basket&type=dynamic&random_type=album','add',_('Add'),'rightbar_related_album'); ?> +<?php echo _('Related Album'); ?></span> + +<span><?php echo Ajax::button('?action=basket&type=dynamic&random_type=genre','add',_('Add'),'rightbar_related_genre'); ?> +<?php echo _('Related Genre'); ?></span> +</div> <?php show_box_bottom(); ?> diff --git a/themes/classic/templates/default.css b/themes/classic/templates/default.css index 962e268d..c4586855 100644 --- a/themes/classic/templates/default.css +++ b/themes/classic/templates/default.css @@ -181,6 +181,11 @@ h3#content_title span { float:left; margin-right:3px; } +#rightbar-bottom span { + padding-left:10px; + display:block; +} + #current_playlist { clear:left; } |