~ubuntu-branches/ubuntu/lucid/ampache/lucid

« back to all changes in this revision

Viewing changes to lib/class/genre.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2009-07-07 07:23:35 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707072335-soq0jyo59mgopzd2
Tags: 3.5.1-0ubuntu1
 * New upstream release.  Summary of new features:  (LP: #377016)
   - Make the PHP error a little clearer for windows users by indicating
     that their version of PHP is < 5.3 (required for windows)
   - Fix random methods not working for Localplay
   - Fix extra space on prefixed albums (Thx ibizaman)
   - Add missing operator on tag and rating searches so they will
     work with other methods (Thx kiehnet@netscape.net)
   - Fix get_art_url() so it returns something... 
   - Fix problem with creating new playlists where it doesn't work
     but appending to an existing did. 
   - Fixed issue with url_to_song, also cleaned up the code a bit
   - Fixed issue with Random All Catalogs
   - Fixed issues with API and Tag methods not working as advertised
   - Fix endless loop in getid3() with malformed genre tags in mp3s
   - Fixed show test page always returning false on web path
   - Update Man page to adhear to newer Debian rules
   - Fixed issue with Videos being incorrectly registered with stats
     and now playing as songs. 
   - Fixed missing > in HTML for song row
 * Bumped Standards-Version to 3.8.2, no changes needed.
 * Bumped debhelper to dh 7.
   - increased debian/compat to 7.
   - debian/rules removed dh_clean -k in favor of dh_prep
 * Lintian complains of FreeMonoMedium.ttf being an embeded fonts package.
   FreeMonoMedium.ttf is actually part of the ttf-freefont package.
   - added ttf-freefont to the Depends section of debian/control.
   - added -XFreeMono-Medium to dh_install in debian/rules.
   - added FreeMono.ttf symbolic link to debian/links.
 * Lintian complains of the wrong file permissions for 
   -  /locale/base/gather-messages.sh, added -Xgather-messages.sh to 
   debian/rules, gather-messages.sh is not used by ampache proper and 
   can be safely removed.  It is only utilized by developers who are 
   creating or editing the translation files.
   -  /locale/pl_PL/LC_MESSAGES/messages.po added find and chmod rule 
   to debian/rules.
   -  /locale/pl_PL/LC_MESSAGES/messages.mo added find and chmod rule 
   to debian/rules.
   -  /docs/CHANGELOG added find and chmod rule to debian/rules.
 * Lintian complains of wrong-name-for-upstream-changelog
   -  install upstream CHANGELOG to /usr/share/ampache/www/docs
   -  added find and gzip -9 rule to debian/rules
   -  added symlink creation to debian/links to link
      /usr/share/ampache/www/docs/CHANGELOG.gz to 
      /usr/share/doc/ampache/changelog.gz  
 * Lacy Marrow has responded and has stated that he is dropping the GPL-3 
   licensing of his work and is now releasing version 5.9.5 of the 
   XSPF JukeBox under the same BSD license that the original version of XSPF 
   Music Player was released under (XSPF JukeBox is based on XSPF Music 
   Player).  So now XSPF Music Player and XSPF JukeBox are now released under
   the same BSD type license.  This closes RC Bug #526719.  Closes: #526719
   - Updated debian/copyright to refect this.
 * Added dh_installman to debian/rules so the manpage now installs correctly.
   - Added debian/ampache.manpages.
 * debian/ampache.config downgraded db_input to medium
 * debian/copyright removed (C) in favor of the word copyright.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 
4
 
 Copyright 2001 - 2007 Ampache.org
5
 
 All Rights Reserved
6
 
 
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.
10
 
 
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.
15
 
 
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. 
19
 
 
20
 
*/
21
 
 
22
 
/**
23
 
 *      Genre Class
24
 
 *      This class takes care of the genre object
25
 
 */
26
 
class Genre {
27
 
 
28
 
        /* Variables */
29
 
        public $id;
30
 
        public $name;
31
 
 
32
 
        /** 
33
 
         * Constructor
34
 
         */
35
 
        public function __construct($genre_id=0) { 
36
 
        
37
 
                if (!$genre_id) { return false; }
38
 
        
39
 
                $this->id       = intval($genre_id);
40
 
                $info           = $this->_get_info();
41
 
                $this->name     = $info['name'];
42
 
 
43
 
 
44
 
        } // Genre
45
 
 
46
 
        /** 
47
 
         * Private Get Info 
48
 
         * This simply returns the information for this genre
49
 
         */
50
 
        private function _get_info() { 
51
 
 
52
 
                $sql = "SELECT * FROM `genre`  WHERE `id`='$this->id'";
53
 
                $db_results = Dba::query($sql);
54
 
                
55
 
                $results = Dba::fetch_assoc($db_results);
56
 
 
57
 
                return $results;
58
 
 
59
 
        } // _get_info
60
 
 
61
 
        /** 
62
 
         * format
63
 
         * this reformats the genre object so it's all purdy and creates a link var
64
 
         */
65
 
        public function format() { 
66
 
 
67
 
                $this->f_link           = "<a href=\"" . Config::get('web_path') . "/genre.php?action=show_genre&amp;genre_id=" . $this->id . "\">" . scrub_out($this->name) . "</a>";
68
 
                
69
 
                $this->play_link        = Config::get('web_path') . '/stream.php?action=genre&amp;genre=' . $this->id;
70
 
                $this->random_link      = Config::get('web_path') . '/stream.php?action=random_genre&amp;genre=' . $this->id; 
71
 
                $this->download_link    = Config::get('web_path') . '/batch.php?action=genre&amp;id=' . $this->id;
72
 
                
73
 
        } // format
74
 
 
75
 
        /**
76
 
         * get_song_count
77
 
         * This returns the number of songs in said genre
78
 
         */
79
 
        public function get_song_count() { 
80
 
 
81
 
                $sql = "SELECT count(`song`.`id`) AS `total` FROM `song` WHERE `genre`='" . $this->id . "'";
82
 
                $db_results = Dba::query($sql);
83
 
 
84
 
                $total_items = Dba::fetch_assoc($db_results);
85
 
                
86
 
                return $total_items['total'];
87
 
 
88
 
        } // get_song_count
89
 
 
90
 
        /**
91
 
         * get_album_count
92
 
         * Returns the number of albums that contain a song of this genre
93
 
         */
94
 
        public function get_album_count() { 
95
 
 
96
 
                $sql = "SELECT COUNT(DISTINCT(song.album)) FROM `song` WHERE `genre`='" . $this->id . "'";
97
 
                $db_results = Dba::query($sql);
98
 
 
99
 
                $total_items = Dba::fetch_row($db_results); 
100
 
 
101
 
                return $total_items['0'];
102
 
 
103
 
        } // get_album_count
104
 
 
105
 
        /**
106
 
         * get_artist_count
107
 
         * Returns the number of artists who have at least one song in this genre
108
 
         */
109
 
        public function get_artist_count() { 
110
 
 
111
 
                $sql = "SELECT COUNT(DISTINCT(`song`.`artist`)) FROM `song` WHERE `genre`='" . $this->id . "'";
112
 
                $db_results = Dba::query($sql);
113
 
 
114
 
                $total_items = Dba::fetch_row($db_results);
115
 
 
116
 
                return $total_items['0'];
117
 
 
118
 
        } // get_artist_count
119
 
 
120
 
        /**
121
 
         * get_songs
122
 
         * This gets all of the songs in this genre and returns an array of song objects
123
 
         */
124
 
        public function get_songs() { 
125
 
 
126
 
                $sql = "SELECT `song`.`id` FROM `song` WHERE `genre`='" . $this->id . "'";
127
 
                $db_results = Dba::query($sql);
128
 
 
129
 
                $results = array();
130
 
 
131
 
                while ($r = Dba::fetch_assoc($db_results)) { 
132
 
                        $results[] = $r['id'];
133
 
                }
134
 
 
135
 
                return $results;
136
 
 
137
 
        } // get_songs
138
 
 
139
 
        /**
140
 
         * get_random_songs
141
 
         * This is the same as get_songs except it returns a random assortment of songs from this
142
 
         * genre
143
 
         */
144
 
        public function get_random_songs() { 
145
 
 
146
 
                $sql = "SELECT `song`.`id` FROM `song` WHERE `genre`='" . $this->id . "' ORDER BY RAND()";
147
 
                $db_results = Dba::query($sql);
148
 
 
149
 
                $results = array();
150
 
 
151
 
                while ($r = Dba::fetch_assoc($db_results)) { 
152
 
                        $results[] = $r['id'];
153
 
                }
154
 
 
155
 
                return $results;
156
 
 
157
 
        } // get_random_songs
158
 
 
159
 
        /**
160
 
         * get_albums
161
 
         * This gets all of the albums that have at least one song in this genre
162
 
         * @package Genre
163
 
         * @catagory Class
164
 
         */
165
 
        function get_albums() { 
166
 
 
167
 
                $sql = "SELECT DISTINCT(`song`.`album`) FROM `song` WHERE `genre`='" . $this->id . "'";
168
 
                $db_results = Dba::query($sql);
169
 
 
170
 
                $results = array();
171
 
 
172
 
                while ($r = Dba::fetch_row($db_results)) { 
173
 
                        $results[] = $r['0'];
174
 
                }
175
 
 
176
 
                return $results;
177
 
 
178
 
        } // get_albums
179
 
 
180
 
        /**
181
 
         * get_artists
182
 
         * This gets all of the artists who have at least one song in this genre
183
 
         */
184
 
        public function get_artists() { 
185
 
 
186
 
                $sql = "SELECT DISTINCT(`song`.`artist`) FROM `song` WHERE `genre`='" . $this->id . "'";
187
 
                $db_results = Dba::query($sql);
188
 
 
189
 
                $results = array();
190
 
 
191
 
                while ($r = Dba::fetch_assoc($db_results)) { 
192
 
                        $results[] = $r['artist']; 
193
 
                }
194
 
                
195
 
                return $results;
196
 
 
197
 
        } // get_artists
198
 
 
199
 
        /**
200
 
         * get_genres
201
 
         * this returns an array of genres based on a sql statement that's passed
202
 
         * @package Genre
203
 
         * @catagory Class
204
 
         */
205
 
        function get_genres($sql) { 
206
 
 
207
 
                $db_results = mysql_query($sql, dbh());
208
 
                
209
 
                $results = array();
210
 
 
211
 
                while ($r = mysql_fetch_assoc($db_results)) { 
212
 
                        $results[] = new Genre($r['id']);
213
 
                }
214
 
 
215
 
                return $results;
216
 
 
217
 
        } // get_genres
218
 
 
219
 
        /**
220
 
         * get_sql_from_match
221
 
         * This is specificly for browsing it takes the match and returns the sql call that we want to use
222
 
         * @package Genre
223
 
         * @catagory Class
224
 
         */
225
 
        function get_sql_from_match($match) { 
226
 
 
227
 
                switch ($match) { 
228
 
                        case 'Show_All':
229
 
                        case 'show_all':
230
 
                        case 'Show_all':
231
 
                                $sql = "SELECT `id` FROM `genre`";
232
 
                        break;
233
 
                        case 'Browse':
234
 
                        case 'show_genres':
235
 
                                $sql = "SELECT `id` FROM `genre`";
236
 
                        break;
237
 
                        default:
238
 
                                $sql = "SELECT `id` FROM `genre` WHERE `name` LIKE '" . Dba::escape($match) . "%'";
239
 
                        break;
240
 
                } // end switch on match
241
 
                                
242
 
                return $sql;
243
 
 
244
 
        } // get_sql_from_match
245
 
         
246
 
} //end of genre class
247
 
 
248
 
?>