4
Copyright 2001 - 2007 Ampache.org
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License v2
9
as published by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
* This class takes care of the genre object
35
public function __construct($genre_id=0) {
37
if (!$genre_id) { return false; }
39
$this->id = intval($genre_id);
40
$info = $this->_get_info();
41
$this->name = $info['name'];
48
* This simply returns the information for this genre
50
private function _get_info() {
52
$sql = "SELECT * FROM `genre` WHERE `id`='$this->id'";
53
$db_results = Dba::query($sql);
55
$results = Dba::fetch_assoc($db_results);
63
* this reformats the genre object so it's all purdy and creates a link var
65
public function format() {
67
$this->f_link = "<a href=\"" . Config::get('web_path') . "/genre.php?action=show_genre&genre_id=" . $this->id . "\">" . scrub_out($this->name) . "</a>";
69
$this->play_link = Config::get('web_path') . '/stream.php?action=genre&genre=' . $this->id;
70
$this->random_link = Config::get('web_path') . '/stream.php?action=random_genre&genre=' . $this->id;
71
$this->download_link = Config::get('web_path') . '/batch.php?action=genre&id=' . $this->id;
77
* This returns the number of songs in said genre
79
public function get_song_count() {
81
$sql = "SELECT count(`song`.`id`) AS `total` FROM `song` WHERE `genre`='" . $this->id . "'";
82
$db_results = Dba::query($sql);
84
$total_items = Dba::fetch_assoc($db_results);
86
return $total_items['total'];
92
* Returns the number of albums that contain a song of this genre
94
public function get_album_count() {
96
$sql = "SELECT COUNT(DISTINCT(song.album)) FROM `song` WHERE `genre`='" . $this->id . "'";
97
$db_results = Dba::query($sql);
99
$total_items = Dba::fetch_row($db_results);
101
return $total_items['0'];
107
* Returns the number of artists who have at least one song in this genre
109
public function get_artist_count() {
111
$sql = "SELECT COUNT(DISTINCT(`song`.`artist`)) FROM `song` WHERE `genre`='" . $this->id . "'";
112
$db_results = Dba::query($sql);
114
$total_items = Dba::fetch_row($db_results);
116
return $total_items['0'];
118
} // get_artist_count
122
* This gets all of the songs in this genre and returns an array of song objects
124
public function get_songs() {
126
$sql = "SELECT `song`.`id` FROM `song` WHERE `genre`='" . $this->id . "'";
127
$db_results = Dba::query($sql);
131
while ($r = Dba::fetch_assoc($db_results)) {
132
$results[] = $r['id'];
141
* This is the same as get_songs except it returns a random assortment of songs from this
144
public function get_random_songs() {
146
$sql = "SELECT `song`.`id` FROM `song` WHERE `genre`='" . $this->id . "' ORDER BY RAND()";
147
$db_results = Dba::query($sql);
151
while ($r = Dba::fetch_assoc($db_results)) {
152
$results[] = $r['id'];
157
} // get_random_songs
161
* This gets all of the albums that have at least one song in this genre
165
function get_albums() {
167
$sql = "SELECT DISTINCT(`song`.`album`) FROM `song` WHERE `genre`='" . $this->id . "'";
168
$db_results = Dba::query($sql);
172
while ($r = Dba::fetch_row($db_results)) {
173
$results[] = $r['0'];
182
* This gets all of the artists who have at least one song in this genre
184
public function get_artists() {
186
$sql = "SELECT DISTINCT(`song`.`artist`) FROM `song` WHERE `genre`='" . $this->id . "'";
187
$db_results = Dba::query($sql);
191
while ($r = Dba::fetch_assoc($db_results)) {
192
$results[] = $r['artist'];
201
* this returns an array of genres based on a sql statement that's passed
205
function get_genres($sql) {
207
$db_results = mysql_query($sql, dbh());
211
while ($r = mysql_fetch_assoc($db_results)) {
212
$results[] = new Genre($r['id']);
221
* This is specificly for browsing it takes the match and returns the sql call that we want to use
225
function get_sql_from_match($match) {
231
$sql = "SELECT `id` FROM `genre`";
235
$sql = "SELECT `id` FROM `genre`";
238
$sql = "SELECT `id` FROM `genre` WHERE `name` LIKE '" . Dba::escape($match) . "%'";
240
} // end switch on match
244
} // get_sql_from_match
246
} //end of genre class