summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-12-15 09:50:33 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-12-15 09:50:33 +0000
commit02a401563b7f9a5f11c8664b621850c52204d7dd (patch)
treeb93a839aca0b334503d96009b9d2464bb62cef62
parentd3176c22e90e0a09b22790036f1f61fc926912c9 (diff)
downloadampache-02a401563b7f9a5f11c8664b621850c52204d7dd.tar.gz
ampache-02a401563b7f9a5f11c8664b621850c52204d7dd.tar.bz2
ampache-02a401563b7f9a5f11c8664b621850c52204d7dd.zip
seperated out the time into its own section on advanced random play, started working on the unplayed, still not finished, started work on highest rated as well, not working yet
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--lib/class/random.class.php41
-rw-r--r--templates/show_random.inc.php25
3 files changed, 49 insertions, 18 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 10ddbc6f..d0ef2427 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.4-Alpha4
+ - Added Length to Advanced Random and removed Minutes from methods
- Added function exists check for session with redirect to /test.php
on failure
- Fixed incorrect extension and stream command being sent when using
diff --git a/lib/class/random.class.php b/lib/class/random.class.php
index 38ff2d13..d46aa6e2 100644
--- a/lib/class/random.class.php
+++ b/lib/class/random.class.php
@@ -259,7 +259,6 @@ class Random {
/* If they've passed -1 as limit then don't get everything */
if ($data['random'] == "-1") { unset($data['random']); }
- elseif ($data['random_type'] == 'length') { /* Rien a faire */ }
else { $limit_sql = "LIMIT " . $limit; }
$where = "1=1 ";
@@ -301,15 +300,28 @@ class Random {
}
$artists_where = ltrim($artists_where," OR");
$sql = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()";
- }
-/* TEMP DISABLE */
-// elseif ($options['random_type'] == 'unplayed') {
-// $uid = $GLOBALS['user']->id;
-// $query = "SELECT song.id,song.size FROM song LEFT JOIN object_count ON song.id = object_count.object_id " .
-// "WHERE ($where) AND ((object_count.object_type='song' AND user = '$uid') OR object_count.count IS NULL ) " .
-// "ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " .
-// "ELSE RAND()*object_count.count END " . $limit_sql;
-// } // If unplayed
+ }
+ elseif ($data['random_type'] == 'unplayed') {
+ $uid = Dba::escape($GLOBALS['user']->id);
+ $sql = "SELECT object_id,COUNT(`id`) AS `total` FROM `object_count` WHERE `user`='$uid' GROUP BY `object_id`";
+ $db_results = Dba::query($sql);
+
+ $in_sql = "`id` IN (";
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $in_sql .= "'" . $row['object_id'] . "',";
+ }
+
+ $in_sql = rtrim($in_sql,',') . ')';
+
+ $sql = "SELECT song.id,song.size,song.time FROM song " .
+ "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql";
+
+ } // If unplayed
+ elseif ($data['random_type'] == 'high_rating') {
+
+
+ }
else {
$sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql";
}
@@ -339,23 +351,24 @@ class Random {
} // if size_limit
// If length really does matter
- if ($data['random_type'] == 'length') {
+ if ($data['length']) {
// base on min, seconds are for chumps and chumpettes
$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['random']) { $fuzzy_time++; continue; }
+ if (($time_total + $new_time) > $data['length']) { $fuzzy_time++; continue; }
$time_total = $time_total + $new_time;
$results[] = $row['id'];
- if (($data['random'] - $time_total) < 2) { return $results; }
+ // If there are less then 2 min of free space return
+ if (($data['length'] - $time_total) < 2) { return $results; }
} // if length does matter
- if (!$data['size_limit'] AND $data['random_type'] != 'length') {
+ if (!$data['size_limit'] AND !$data['length']) {
$results[] = $row['id'];
}
diff --git a/templates/show_random.inc.php b/templates/show_random.inc.php
index b0500643..b360d396 100644
--- a/templates/show_random.inc.php
+++ b/templates/show_random.inc.php
@@ -38,9 +38,24 @@
<option value="-1"><?php echo _('All'); ?></option>
</select>
</td>
- <td rowspan="4" valign="top"><?php echo _('From genre'); ?></td>
- <td rowspan="4">
- <?php show_genre_select('genre[]','','5'); ?>
+ <td rowspan="5" valign="top"><?php echo _('From genre'); ?></td>
+ <td rowspan="5">
+ <?php show_genre_select('genre[]','','6'); ?>
+ </td>
+</tr>
+<tr>
+ <td><?php echo _('Length'); ?></td>
+ <td>
+ <select name="length">
+ <option value="0"><?php echo _('Unlimited'); ?></option>
+ <option value="15">15 <?php echo _('minutes'); ?></option>
+ <option value="30">30 <?php echo _('minutes'); ?></option>
+ <option value="60">1 <?php echo _('hours'); ?></option>
+ <option value="120">2 <?php echo _('hours'); ?></option>
+ <option value="240">4 <?php echo _('hours'); ?></option>
+ <option value="480">8 <?php echo _('hours'); ?></option>
+ <option value="960">16 <?php echo _('hours'); ?></option>
+ </select>
</td>
</tr>
<tr>
@@ -51,7 +66,9 @@
<option value="unplayed"><?php echo _('Less Played'); ?></option>
<option value="full_album"><?php echo _('Full Albums'); ?></option>
<option value="full_artist"><?php echo _('Full Artist'); ?></option>
- <option value="length"><?php echo _('Minutes'); ?></option>
+ <?php if (Config::get('ratings')) { ?>
+ <option value="high_rating"><?php echo _('Highest Rated'); ?></option>
+ <?php } ?>
</select>
</td>
</tr>