diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-08-13 06:51:32 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-08-13 06:51:32 +0000 |
commit | 53cab4e5ba7e791c0c759a91895dffb072441017 (patch) | |
tree | 54a9eb268cdc83d4d8c3d809cda91a33d03eb42d /lib/class/genre.class.php | |
parent | e7fea90327419214531371543662056c1398470d (diff) | |
download | ampache-53cab4e5ba7e791c0c759a91895dffb072441017.tar.gz ampache-53cab4e5ba7e791c0c759a91895dffb072441017.tar.bz2 ampache-53cab4e5ba7e791c0c759a91895dffb072441017.zip |
initial genre browsing and improved artists/albums browse code (made it consistent)
Diffstat (limited to 'lib/class/genre.class.php')
-rw-r--r-- | lib/class/genre.class.php | 106 |
1 files changed, 104 insertions, 2 deletions
diff --git a/lib/class/genre.class.php b/lib/class/genre.class.php index 0b57a473..d5165dcb 100644 --- a/lib/class/genre.class.php +++ b/lib/class/genre.class.php @@ -71,8 +71,11 @@ class Genre { */ function format_genre() { - - + $this->link = $this->name; + + $this->play_link = conf('web_path') . "/song.php?action=genre&genre=" . $this->id; + $this->random_link = conf('web_path') . "/song.php?action=random_genre&genre=" . $this->id; + } // format_genre /** @@ -83,7 +86,12 @@ class Genre { */ function get_song_count() { + $sql = "SELECT count(song.id) FROM song WHERE genre='" . $this->id . "'"; + $db_results = mysql_query($sql, dbh()); + + $total_items = mysql_fetch_array($db_results); + return $total_items[0]; } // get_song_count @@ -95,11 +103,44 @@ class Genre { */ function get_songs() { + $sql = "SELECT song.id FROM song WHERE genre='" . $this->id . "'"; + $db_results = mysql_query($sql, dbh()); + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r['id']; + } + + return $results; } // get_songs /** + * get_random_songs + * This is the same as get_songs except it returns a random assortment of songs from this + * genre + * @package Genre + * @catagory Class + */ + function get_random_songs() { + + $limit = rand(1,$this->get_song_count()); + + $sql = "SELECT song.id FROM song WHERE genre='" . $this->id . "' ORDER BY RAND() LIMIT $limit"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r['id']; + } + + return $results; + + } // get_random_songs + + /** * get_albums * This gets all of the albums that have at least one song in this genre * @package Genre @@ -123,6 +164,67 @@ class Genre { } // get_artists + /** + * get_genres + * this returns an array of genres based on a sql statement that's passed + * @package Genre + * @catagory Class + */ + function get_genres($sql) { + + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = new Genre($r['id']); + } + + return $results; + + } // get_genres + + /** + * get_sql_from_match + * This is specificly for browsing it takes the match and returns the sql call that we want to use + * @package Genre + * @catagory Class + */ + function get_sql_from_match($match) { + + switch ($match) { + case 'Show_All': + case 'show_all': + $sql = "SELECT id FROM genre"; + break; + case 'Browse': + case 'show_genres': + $sql = "SELECT id FROM genre"; + break; + default: + $sql = "SELECT id FROM genre WHERE name LIKE '" . sql_escape($match) . "%'"; + break; + } // end switch on match + + return $sql; + + } // get_sql_from_match + + + /** + * show_match_list + * This shows the Alphabet list and any other 'things' that genre by need at the top of every browse + * page + * @package Genre + * @catagory Class + */ + function show_match_list($match) { + + show_alphabet_list('genre','browse.php',$match,'genre'); + show_alphabet_form($match,_("Show Genres starting with"),"browse.php?action=genre&match=$match"); + + } // show_match_list + } //end of genre class ?> |