summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/album.class.php36
-rw-r--r--lib/class/random.class.php15
2 files changed, 19 insertions, 32 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 4f6e1ff2..a7e888e9 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -418,30 +418,32 @@ class Album extends database_object {
} // update
/**
- * get_random_albums
- * This returns a random number of albums from the catalogs
- * this is used by the index to return some 'potential' albums to play
+ * get_random
+ *
+ * This returns a number of random albums.
*/
- public static function get_random_albums($count=6) {
-
- $sql = 'SELECT `id` FROM `album` ORDER BY RAND() LIMIT ' . ($count*2);
+ public static function get_random($count = 1, $with_art = false) {
+ $results = false;
+
+ if ($with_art) {
+ $sql = 'SELECT `album`.`id` FROM `album` LEFT JOIN `image` ' .
+ "ON (`image`.`object_type` = 'album' AND " .
+ '`image`.`object_id` = `album`.`id`) ' .
+ 'WHERE `image`.`id` IS NOT NULL ';
+ }
+ else {
+ $sql = 'SELECT `id` FROM `album` ';
+ }
+
+ $sql .= 'ORDER BY RAND() LIMIT ' . intval($count);
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $art = new Art($row['id'], 'album');
- $art->get_db();
- if ($art->raw) {
- $results[] = $row['id'];
- }
+ $results[] = $row['id'];
}
- if (count($results) < $count) { return false; }
-
- $results = array_slice($results, 0, $count);
-
return $results;
-
- } // get_random_albums
+ }
} //end of album class
diff --git a/lib/class/random.class.php b/lib/class/random.class.php
index a4756db9..7b525641 100644
--- a/lib/class/random.class.php
+++ b/lib/class/random.class.php
@@ -45,21 +45,6 @@ class Random implements media {
} // constructor
/**
- * album
- * This returns the ID of a random album, nothing special
- */
- public static function album() {
-
- $sql = "SELECT `id` FROM `album` ORDER BY RAND() LIMIT 1";
- $db_results = Dba::read($sql);
-
- $results = Dba::fetch_assoc($db_results);
-
- return $results['id'];
-
- } // album
-
- /**
* artist
* This returns the ID of a random artist, nothing special here for now
*/