summaryrefslogtreecommitdiffstats
path: root/lib/class/random.class.php
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-09-25 04:17:03 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-09-25 04:17:03 +0000
commit851c035d4eedff682ec26eefb3e87545d0b07fd3 (patch)
treea6a5e382586e3a9bfcbc6feab8b8cc4ceb8c3d2c /lib/class/random.class.php
parent4fecf43894deb10a980441edf72dfa567b64a23d (diff)
downloadampache-851c035d4eedff682ec26eefb3e87545d0b07fd3.tar.gz
ampache-851c035d4eedff682ec26eefb3e87545d0b07fd3.tar.bz2
ampache-851c035d4eedff682ec26eefb3e87545d0b07fd3.zip
fixed album random and by min random
Diffstat (limited to 'lib/class/random.class.php')
-rw-r--r--lib/class/random.class.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/class/random.class.php b/lib/class/random.class.php
index a51d5d6d..4b0efe84 100644
--- a/lib/class/random.class.php
+++ b/lib/class/random.class.php
@@ -258,7 +258,7 @@ class Random {
}
/* If they've passed -1 as limit then don't get everything */
- if ($data['limit'] == "-1") { unset($data['limit']); }
+ if ($data['random'] == "-1") { unset($data['random']); }
elseif ($data['random_type'] == 'length') { /* Rien a faire */ }
else { $limit_sql = "LIMIT " . $limit; }
@@ -266,12 +266,15 @@ class Random {
if (is_array($matchlist)) {
foreach ($matchlist as $type => $value) {
if (is_array($value)) {
+ $where .= "(";
foreach ($value as $v) {
+ if (!strlen($v)) { continue; }
$v = Dba::escape($v);
if ($v != $value[0]) { $where .= " OR $type='$v' "; }
else { $where .= " AND ( $type='$v'"; }
}
- $where .= " ) ";
+ $where .= ")";
+ $where = rtrim($where,"()");
}
elseif (strlen($value)) {
$value = Dba::escape($value);
@@ -282,14 +285,15 @@ class Random {
if ($data['random_type'] == 'full_album') {
- $query = "SELECT` album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " .
+ $query = "SELECT `album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " .
"WHERE $where GROUP BY `song`.`album` ORDER BY RAND() $limit_sql";
$db_results = Dba::query($query);
- while ($row = Dba::fetch_row($db_results)) {
- $albums_where .= " OR `song`.`album`=" . $row[0];
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $albums_where .= " OR `song`.`album`=" . $row['id'];
}
$albums_where = ltrim($albums_where," OR");
$sql = "SELECT `song`.`id`,`song`.`size`,`song`.`time` FROM `song` WHERE $albums_where ORDER BY `song`.`album`,`song`.`track` ASC";
+
}
elseif ($data['random_type'] == 'full_artist') {
$query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " .
@@ -318,7 +322,7 @@ class Random {
$results = array();
while ($row = Dba::fetch_assoc($db_results)) {
-
+
// If size limit is specified
if ($data['size_limit']) {
// Convert
@@ -343,14 +347,14 @@ class Random {
$new_time = floor($row['time'] / 60);
if ($fuzzy_time > 10) { return $results; }
-
+
// If the new one would go voer skip!
- if (($time_total + $new_time) > $data['limit']) { $fuzzy_time++; continue; }
+ if (($time_total + $new_time) > $data['random']) { $fuzzy_time++; continue; }
$time_total = $time_total + $new_time;
$results[] = $row['id'];
- if (($data['limit'] - $time_total) < 2) { return $results; }
+ if (($data['random'] - $time_total) < 2) { return $results; }
} // if length does matter