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 | |
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')
-rw-r--r-- | lib/class/catalog.class.php | 35 | ||||
-rw-r--r-- | lib/class/genre.class.php | 106 | ||||
-rw-r--r-- | lib/ui.lib.php | 37 |
3 files changed, 171 insertions, 7 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 4649ae44..bade7811 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1066,6 +1066,7 @@ class Catalog { $this->clean_albums(); $this->clean_stats(); $this->clean_artists(); + $this->clean_genres(); $this->clean_flagged(); } // update_remote_catalog @@ -1156,6 +1157,7 @@ class Catalog { $this->clean_stats(); $this->clean_playlists(); $this->clean_flagged(); + $this->clean_genres(); /* Return dead files, so they can be listed */ echo "<b>" . _("Catalog Clean Done") . " [" . count($dead_files) . "] " . _("files removed") . "</b><br />\n"; @@ -1164,6 +1166,39 @@ class Catalog { } //clean_catalog + /** + * clean_genres + * This functions cleans up unused genres + * @package Catalog + * @catagory Clean + */ + function clean_genres() { + + /* Mysql 3.23 doesn't support our cool query so we have to do it a different way */ + if (preg_match("/^3\./",mysql_get_server_info())) { + $sql = "SELECT genre.id FROM genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_row($db_results)) { + $results[] = $r; + } + + foreach ($results as $dead) { + + $sql = "DELETE FROM genre WHERE id='$dead[0]'"; + $db_results = mysql_query($sql,dbh()); + } + return true; + } + + /* Do a complex delete to get albums where there are no songs */ + $sql = "DELETE FROM genre USING genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL"; + $db_results = mysql_query($sql, dbh()); + + } // clean_genres + /*! @function clean_albums 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 ?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 85bae998..3b1abb19 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -171,6 +171,8 @@ function show_menu_items ($high) { */ function show_browse_menu($highlight) { + $highlight = ucfirst($highlight); + include(conf('prefix'). "/templates/show_browse_menu.inc"); } // show_browse_menu @@ -283,7 +285,7 @@ function return_referer() { * shows the A-Z,0-9 lists for * albums and artist pages */ -function show_alphabet_list ($type,$script="artist.php",$selected="false") { +function show_alphabet_list ($type,$script="artist.php",$selected="false",$action='match') { $list = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,"0"); @@ -293,20 +295,33 @@ function show_alphabet_list ($type,$script="artist.php",$selected="false") { echo "<div class=\"alphabet\">"; foreach ($list as $l) { $style_name = "style_" . strtolower($l); - echo "<a href=\"". conf('web_path') ."/$script?action=match&match=$l\" " . ${$style_name} . ">$l</a> | \n"; + echo "<a href=\"". conf('web_path') ."/$script?action=$action&match=$l\" " . ${$style_name} . ">$l</a> | \n"; } - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Browse\" $style_browse>" . _("Browse") . "</a> | \n"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Browse\" $style_browse>" . _("Browse") . "</a> | \n"; if ($script == "albums.php") { - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_missing_art\" $style_show_missing_art>" . _("Show w/o art") . "</a> | \n"; } // if we are on the albums page - echo " <a href=\"". conf('web_path') ."/$script?action=match&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; + echo " <a href=\"". conf('web_path') ."/$script?action=$action&match=Show_all\" $style_show_all>" . _("Show all") . "</a>"; echo "</div>\n"; } // show_alphabet_list /** + * show_alphabet_form + * this shows the spiffy little form that acts as a "quick search" when browsing + * @package General + * @catagory Display + */ +function show_alphabet_form($match, $text, $action) { + + require (conf('prefix') . '/templates/show_alphabet_form.inc.php'); + +} // show_alphabet_form + + +/** * show_local_control * shows the controls * for localplay @@ -676,5 +691,17 @@ function img_resize($image,$size,$type){ } // img_resize +/** + * show_genres + * this shows the 'many' genre form, it takes an array of genre objects and the view object + * @package Genre + * @catagory Display + */ +function show_genres($genres,$view) { + + require (conf('prefix') . '/templates/show_genres.inc.php'); + +} // show_genres + ?> |