summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-09-17 03:11:06 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-09-17 03:11:06 +0000
commit88562955f9c96d8d347acc8c12cdf33adab04f94 (patch)
treead90a912041f32aeeef6fb662ad4d91c67c34c0b
parentd1dcfcbc903153007fff2c155248046ecfbdc76a (diff)
downloadampache-88562955f9c96d8d347acc8c12cdf33adab04f94.tar.gz
ampache-88562955f9c96d8d347acc8c12cdf33adab04f94.tar.bz2
ampache-88562955f9c96d8d347acc8c12cdf33adab04f94.zip
added sorting on most objects in most views, report bugs if you find points where sorting fails
-rw-r--r--browse.php3
-rw-r--r--lib/class/browse.class.php147
-rw-r--r--server/browse.ajax.php13
-rw-r--r--templates/show_album.inc.php8
-rw-r--r--templates/show_albums.inc.php4
-rw-r--r--templates/show_artist.inc.php6
-rw-r--r--templates/show_artists.inc.php10
-rw-r--r--templates/show_live_streams.inc.php6
-rw-r--r--templates/show_playlists.inc.php2
-rw-r--r--templates/show_songs.inc.php8
10 files changed, 157 insertions, 50 deletions
diff --git a/browse.php b/browse.php
index 132af334..5c80034a 100644
--- a/browse.php
+++ b/browse.php
@@ -42,13 +42,11 @@ switch($_REQUEST['action']) {
case 'file':
case 'album':
Browse::set_type('album');
- Browse::set_sort('name');
$album_ids = Browse::get_objects();
Browse::show_objects($album_ids);
break;
case 'artist':
Browse::set_type('artist');
- Browse::set_sort('name');
$artist_ids = Browse::get_objects();
Browse::show_objects($artist_ids);
break;
@@ -59,7 +57,6 @@ switch($_REQUEST['action']) {
break;
case 'song':
Browse::set_type('song');
- Browse::set_sort('title');
$song_ids = Browse::get_objects();
Browse::show_objects($song_ids);
break;
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php
index b7a54757..3ed20eae 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -123,7 +123,7 @@ class Browse {
switch ($_SESSION['browse']['type']) {
case 'song':
- $valid_array = array('title','year');
+ $valid_array = array('title','year','track','time');
break;
case 'artist':
$valid_array = array('name');
@@ -131,6 +131,12 @@ class Browse {
case 'album':
$valid_array = array('name','year');
break;
+ case 'playlist':
+ $valid_array = array('name');
+ break;
+ case 'live_stream':
+ $valid_array = array('name','call_sign','frequency');
+ break;
} // end switch
// If it's not in our list, smeg off!
@@ -139,12 +145,18 @@ class Browse {
}
if ($_SESSION['browse']['sort'][$sort] == 'DESC') {
- $_SESSION['browse']['sort'][$sort] = 'ASC';
+ // Reset it till I can figure out how to interface the hotness
+ $_SESSION['browse']['sort'] = array();
+ $_SESSION['browse']['sort'][$sort] = 'ASC';
}
else {
+ // Reset it till I can figure out how to interface the hotness
+ $_SESSION['browse']['sort'] = array();
$_SESSION['browse']['sort'][$sort] = 'DESC';
}
+ self::resort_objects();
+
} // set_sort
/**
@@ -201,6 +213,42 @@ class Browse {
} // get_objects
/**
+ * get_base_sql
+ * This returns the base SQL (select + from) for the different types
+ */
+ private static function get_base_sql() {
+
+ // Get our base SQL must always return ID
+ switch ($_SESSION['browse']['type']) {
+ case 'album':
+ $sql = "SELECT `album`.`id` FROM `album` ";
+ break;
+ case 'artist':
+ $sql = "SELECT `artist`.`id` FROM `artist` ";
+ break;
+ case 'genre':
+ $sql = "SELECT `genre`.`id` FROM `genre` ";
+ break;
+ case 'user':
+ $sql = "SELECT `user`.`id` FROM `user` ";
+ break;
+ case 'live_stream':
+ $sql = "SELECT `live_stream`.`id` FROM `live_stream` ";
+ break;
+ case 'playlist':
+ $sql = "SELECT `playlist`.`id` FROM `playlist` ";
+ break;
+ case 'song':
+ default:
+ $sql = "SELECT `song`.`id` FROM `song` ";
+ break;
+ } // end base sql
+
+ return $sql;
+
+ } // get_base_sql
+
+ /**
* get_sql
* This returns the sql statement we are going to use this has to be run
* every time we get the objects because it depends on the filters and the
@@ -208,31 +256,7 @@ class Browse {
*/
public static function get_sql() {
- // Get our base SQL must always return ID
- switch ($_SESSION['browse']['type']) {
- case 'album':
- $sql = "SELECT `album`.`id` FROM `album` ";
- break;
- case 'artist':
- $sql = "SELECT `artist`.`id` FROM `artist` ";
- break;
- case 'genre':
- $sql = "SELECT `genre`.`id` FROM `genre` ";
- break;
- case 'user':
- $sql = "SELECT `user`.`id` FROM `user` ";
- break;
- case 'live_stream':
- $sql = "SELECT `live_stream`.`id` FROM `live_stream` ";
- break;
- case 'playlist':
- $sql = "SELECT `playlist`.`id` FROM `playlist` ";
- break;
- case 'song':
- default:
- $sql = "SELECT `song`.`id` FROM `song` ";
- break;
- } // end base sql
+ $sql = self::get_base_sql();
// No sense to go further if we don't have filters
if (is_array($_SESSION['browse']['filter'])) {
@@ -383,7 +407,13 @@ class Browse {
case 'year':
$sql = "`song`.`year`";
break;
- default:
+ case 'time':
+ $sql = "`song`.`time`";
+ break;
+ case 'track':
+ $sql = "`song`.`track`";
+ break;
+ default:
// Rien a faire
break;
} // end switch
@@ -405,6 +435,26 @@ class Browse {
break;
} // end switch
break;
+ case 'playlist':
+ switch ($field) {
+ case 'name':
+ $sql = "`playlist`.`name`";
+ break;
+ } // end switch
+ break;
+ case 'live_stream':
+ switch ($field) {
+ case 'name':
+ $sql = "`live_stream`.`name`";
+ break;
+ case 'call_sign':
+ $sql = "`live_stream`.`call_sign`";
+ break;
+ case 'frequency':
+ $sql = "`live_stream`.`frequency`";
+ break;
+ } // end switch
+ break;
default:
// Rien a faire
break;
@@ -501,4 +551,45 @@ class Browse {
} // save_objects
+ /**
+ * resort_objects
+ * This takes the existing objects, looks at the current
+ * sort method and then re-sorts them This is internally
+ * called by the set_sort() function
+ */
+ private static function resort_objects() {
+
+ // First pull the objects
+ $objects = self::get_saved();
+
+ foreach ($objects as $object_id) {
+ $object_id = Dba::escape($object_id);
+ $where_sql .= "`id`='$object_id' OR";
+ }
+ $where_sql = rtrim($where_sql,'OR');
+
+ $sql = self::get_base_sql() . ' WHERE ' . $where_sql;
+
+ $order_sql = "ORDER BY ";
+
+ foreach ($_SESSION['browse']['sort'] as $key=>$value) {
+ $order_sql .= self::sql_sort($key,$value);
+ }
+ // Clean her up
+ $order_sql = rtrim($order_sql,"ORDER BY ");
+ $order_sql = rtrim($order_sql,",");
+
+ $sql = $sql . $order_sql;
+ $db_results = Dba::query($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
+
+ self::save_objects($results);
+
+ return true;
+
+ } // resort_objects
+
} // browse
diff --git a/server/browse.ajax.php b/server/browse.ajax.php
index 57019584..b7514152 100644
--- a/server/browse.ajax.php
+++ b/server/browse.ajax.php
@@ -43,6 +43,19 @@ switch ($_REQUEST['action']) {
$results['browse_content'] = ob_get_contents();
ob_end_clean();
break;
+ case 'set_sort':
+ if ($_REQUEST['sort']) {
+ Browse::set_sort($_REQUEST['sort']);
+ }
+
+ // Refresh the browse div with our new hotness
+ $object_ids = Browse::get_saved();
+
+ ob_start();
+ Browse::show_objects($object_ids);
+ $results['browse_content'] = ob_get_contents();
+ ob_end_clean();
+ break;
default:
$results['rfc3514'] = '0x1';
break;
diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php
index 3a840db3..b2421511 100644
--- a/templates/show_album.inc.php
+++ b/templates/show_album.inc.php
@@ -61,9 +61,11 @@ $title = scrub_out($album->name) . '&nbsp;(' . $album->year . ')&nbsp;--&nbsp;'
<div id="additional_information">
&nbsp;
</div>
+<div id="browse_content">
<?php
- show_box_top($album->name . ' ' . _('Songs'));
$object_ids = $album->get_songs();
- require Config::get('prefix') . '/templates/show_songs.inc.php';
- show_box_bottom();
+ Browse::set_type('song');
+ Browse::save_objects($object_ids);
+ Browse::show_objects($object_ids);
?>
+</div>
diff --git a/templates/show_albums.inc.php b/templates/show_albums.inc.php
index 7a692caf..0df1393f 100644
--- a/templates/show_albums.inc.php
+++ b/templates/show_albums.inc.php
@@ -32,10 +32,10 @@ $ajax_url = Config::get('ajax_url');
<?php if (Browse::get_filter('show_art')) { ?>
<th><?php echo _('Cover'); ?></th>
<?php } ?>
- <th><?php echo _('Album'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=name',_('Album'),'album_sort_name'); ?></th>
<th><?php echo _('Artist'); ?></th>
<th><?php echo _('Songs'); ?></th>
- <th><?php echo _('Year'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=year',_('Year'),'album_sort_year'); ?></th>
<th><?php echo _('Actions'); ?></th>
</tr>
<?php
diff --git a/templates/show_artist.inc.php b/templates/show_artist.inc.php
index ae5d5006..9c598c08 100644
--- a/templates/show_artist.inc.php
+++ b/templates/show_artist.inc.php
@@ -25,5 +25,9 @@ require Config::get('prefix') . '/templates/show_artist_box.inc.php';
?>
<div id="browse_content">
-<?php Browse::set_type('album'); Browse::show_objects($albums); ?>
+<?php
+ Browse::set_type('album');
+ Browse::save_objects($albums);
+ Browse::show_objects($albums);
+?>
</div>
diff --git a/templates/show_artists.inc.php b/templates/show_artists.inc.php
index da95eadc..3b7c1344 100644
--- a/templates/show_artists.inc.php
+++ b/templates/show_artists.inc.php
@@ -28,11 +28,11 @@ $web_path = Config::get('web_path');
</td>
</tr>
<tr class="table-header">
- <td><?php echo _('Add'); ?>
- <td><?php echo _('Artist'); ?></td>
- <td> <?php echo _('Songs'); ?> </td>
- <td> <?php echo _('Albums'); ?> </td>
- <td> <?php echo _('Action'); ?> </td>
+ <th><?php echo _('Add'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=name',_('Artist'),'artist_sort_name'); ?></th>
+ <th> <?php echo _('Songs'); ?> </th>
+ <th> <?php echo _('Albums'); ?> </th>
+ <th> <?php echo _('Action'); ?> </th>
</tr>
<?php
/* Foreach through every artist that has been passed to us */
diff --git a/templates/show_live_streams.inc.php b/templates/show_live_streams.inc.php
index b69e81d3..d46a3b15 100644
--- a/templates/show_live_streams.inc.php
+++ b/templates/show_live_streams.inc.php
@@ -29,9 +29,9 @@ $web_path = Config::get('web_path');
</tr>
<tr class="table-header">
<th><?php echo _('Add'); ?></th>
- <th><?php echo _('Name'); ?></th>
- <th><?php echo _('Callsign'); ?></th>
- <th><?php echo _('Frequency'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=name',_('Name'),'live_stream_sort_name'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=call_sign',_('Callsign'),'live_stream_call_sign'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=frequency',_('Frequency'),'live_stream_frequency'); ?></th>
<th><?php echo _('Genre'); ?></th>
<th><?php echo _('Action'); ?> </th>
</tr>
diff --git a/templates/show_playlists.inc.php b/templates/show_playlists.inc.php
index 81b7b22d..ce577508 100644
--- a/templates/show_playlists.inc.php
+++ b/templates/show_playlists.inc.php
@@ -28,7 +28,7 @@
</tr>
<tr class="table-header">
<th>&nbsp;</th>
- <th><?php echo _('Playlist Name'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=name',_('Playlist Name'),'playlist_sort_name'); ?></th>
<th><?php echo _('# Songs'); ?></th>
<th><?php echo _('Owner'); ?></th>
<th><?php echo _('Actions'); ?></th>
diff --git a/templates/show_songs.inc.php b/templates/show_songs.inc.php
index 2ad73b95..a104f1f2 100644
--- a/templates/show_songs.inc.php
+++ b/templates/show_songs.inc.php
@@ -31,14 +31,14 @@ $ajax_url = Config::get('ajax_url');
</tr>
<tr class="table-header">
<th><?php echo _('Add'); ?></th>
- <th onclick="ajaxPut('<?php echo $ajax_url; ?>?action=browse&amp;sort=title');return true;" style="cursor:pointer;">
- <?php echo _('Song Title'); ?>
+ <th>
+ <?php echo Ajax::text('?page=browse&action=set_sort&sort=title',_('Song Title'),'sort_song_title'); ?>
</th>
<th><?php echo _('Artist'); ?></th>
<th><?php echo _('Album'); ?></th>
<th><?php echo _('Genre'); ?></th>
- <th><?php echo _('Track'); ?></th>
- <th><?php echo _('Time'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=track',_('Track'),'sort_song_track'); ?></th>
+ <th><?php echo Ajax::text('?page=browse&action=set_sort&sort=time',_('Time'),'sort_song_time'); ?></th>
<th><?php echo _('Action'); ?></th>
</tr>
<?php