diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-31 04:31:42 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-07-31 04:31:42 +0000 |
commit | 652474071e711585fec6b8495b3f22a927c9672e (patch) | |
tree | 38186cbd08376625d484d8f8f99e5b2513520c32 | |
parent | d48a431606385a618a31eb007b1527c8d8dd075d (diff) | |
download | ampache-652474071e711585fec6b8495b3f22a927c9672e.tar.gz ampache-652474071e711585fec6b8495b3f22a927c9672e.tar.bz2 ampache-652474071e711585fec6b8495b3f22a927c9672e.zip |
added paging on all song displays
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/browse.class.php | 59 | ||||
-rw-r--r-- | search.php | 3 | ||||
-rw-r--r-- | server/ajax.server.php | 9 | ||||
-rw-r--r-- | templates/list_header.inc.php | 48 | ||||
-rw-r--r-- | templates/show_songs.inc.php | 2 | ||||
-rw-r--r-- | themes/classic/templates/default.css | 1 |
7 files changed, 91 insertions, 32 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index f391a9a7..a8a8c1d7 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Alpha2 + - Added paging on all song displays including search - Fixed searching via quicksearch bar - Added 'Your' playlists to leftbar with play and view links - Fixed clear now playing diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 375afe8a..a5ea13b2 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -31,6 +31,8 @@ class Browse { // Public static vars that are cached public static $sql; + public static $start = '0'; + public static $total_objects; /** * constructor @@ -121,6 +123,29 @@ class Browse { } // set_sort /** + * set_start + * This sets the start point for our show functions + */ + public static function set_start($start) { + + self::$start = intval($start); + + } // set_start + + /** + * get_saved + * This looks in the session for the saved + * stuff and returns what it finds + */ + public static function get_saved() { + + $objects = $_SESSION['browse']['save']; + + return $objects; + + } // get_saved + + /** * get_objects * This gets an array of the ids of the objects that we are * currently browsing by it applies the sql and logic based @@ -136,15 +161,15 @@ class Browse { $results = array(); while ($data = Dba::fetch_assoc($db_results)) { - // If we've hit our offset limit - if (count($results) >= $GLOBALS['user']->prefs['offset_limit']) { return $results; } - // Make sure that this object passes the logic filter if (self::logic_filter($data['id'])) { $results[] = $data['id']; } } // end while - + + // Save what we've found and then return it + self::save_objects($results); + return $results; } // get_objects @@ -340,7 +365,17 @@ class Browse { * and requires the correct template based on the * type that we are currently browsing */ - public static function show_objects($object_ids) { + public static function show_objects($object_ids='') { + + $object_ids = $object_ids ? $object_ids : self::get_saved(); + + // Reset the total items + self::$total_objects = count($object_ids); + + // Limit is based on the users preferences + $limit = $GLOBALS['user']->prefs['offset_limit'] ? $GLOBALS['user']->prefs['offset_limit'] : '25'; + + $object_ids = array_slice($object_ids,self::$start,$limit); switch ($_SESSION['browse']['type']) { case 'song': @@ -380,4 +415,18 @@ class Browse { } // show_object + /** + * save_objects + * This takes the full array of object ides, often passed into show and then + * if nessecary it saves them into the session + */ + public static function save_objects($object_ids) { + + // save these objects + $_SESSION['browse']['save'] = $object_ids; + self::$total_objects = count($object_ids); + return true; + + } // save_objects + } // browse @@ -44,7 +44,10 @@ switch ($_REQUEST['action']) { require_once Config::get('prefix') . '/templates/show_search.inc.php'; $results = run_search($_REQUEST); Browse::set_type('song'); + + echo "<div id=\"browse_content\">"; Browse::show_objects($results); + echo "</div>"; break; case 'save_as_track': $playlist_id = save_search($_REQUEST); diff --git a/server/ajax.server.php b/server/ajax.server.php index 1773db9b..c4227361 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -307,6 +307,15 @@ switch ($action) { $xml_doc = xml_from_array($results); echo $xml_doc; break; + case 'page': + Browse::set_start($_REQUEST['start']); + + ob_start(); + Browse::show_objects(); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); + echo xml_from_array($results); + break; case 'sidebar': switch ($_REQUEST['button']) { case 'home': diff --git a/templates/list_header.inc.php b/templates/list_header.inc.php index 7fb13a57..fb86a932 100644 --- a/templates/list_header.inc.php +++ b/templates/list_header.inc.php @@ -26,30 +26,28 @@ * to layout this page. */ -/* We must have Some Items, if none passed use sesison information */ -if (!$total_items) { $total_items = $_SESSION['view_total_items']; } - - -/* Calculate the Next/Prev Pages */ +// Pull these variables out to allow shorthand (easier for lazy programmers) +$limit = $GLOBALS['user']->prefs['offset_limit'] ? $GLOBALS['user']->prefs['offset_limit'] : '25'; +$start = Browse::$start; +$total = Browse::$total_objects; // Next -$next_offset = $GLOBALS['view']->offset + $GLOBALS['view']->offset_limit; -if ($next_offset > $total_items) { $next_offset = $GLOBALS['view']->offset; } +$next_offset = $start + $limit; +if ($next_offset > $total) { $next_offset = $start; } // Prev -$prev_offset = $GLOBALS['view']->offset - $GLOBALS['view']->offset_limit; +$prev_offset = $start - $limit; if ($prev_offset < 0) { $prev_offset = '0'; } /* Calculate how many pages total exist */ -if (!$GLOBALS['view']->offset_limit) { $GLOBALS['view']->offset_limit = '50'; } -$pages = ceil($total_items/$GLOBALS['view']->offset_limit); +$pages = ceil($total/$limit); /* Calculate current page and how many we have on each side */ $page_data = array('up'=>array(),'down'=>array()); // Can't Divide by 0 -if ($GLOBALS['view']->offset > 0) { - $current_page = floor($GLOBALS['view']->offset/$GLOBALS['view']->offset_limit); +if ($start> 0) { + $current_page = floor($start/$limit); } else { $current_page = 0; @@ -72,16 +70,16 @@ $page = $current_page+1; $i = 0; /* While we have pages left */ while ($page <= $pages) { - if ($page * $GLOBALS['view']->offset_limit > $total_items) { break; } + if ($page * $limit > $total) { break; } if ($i == '15') { $key = $pages - 1; if (!$page_data['up'][$key]) { $page_data['up'][$key] = '...'; } - $page_data['up'][$pages] = ($pages-1) * $GLOBALS['view']->offset_limit; + $page_data['up'][$pages] = ($pages-1) * $limit; break; } $i++; $page = $page + 1; - $page_data['up'][$page] = ($page-1) * $GLOBALS['view']->offset_limit; + $page_data['up'][$page] = ($page-1) * $limit; } // end while // Sort These Arrays of Hotness @@ -99,15 +97,15 @@ if (!isset($matches['1'])) { } $action = "action=" . scrub_in($_REQUEST['action']); -$script = conf('web_path') . "/" . $admin_menu . $matches[1]; +$script = Config::get('web_path') . "/" . $admin_menu . $matches[1]; // are there enough items to even need this view? -if (($pages > 1) && ($_SESSION['view_script'])) { +if ($pages > 1) { ?> <table class="list-header" cellpadding="1" cellspacing="0" width="100%"> <tr> <td valign="top"> - <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $prev_offset; ?>&keep_view=true">[<?php echo _('Prev'); ?>]</a> + <?php echo Ajax::text('?action=page&start=' . $prev_offset,'[' . _('Prev') . ']','browse_prev','','list-header'); ?> </td> <td align="center"> <?php @@ -133,30 +131,28 @@ if (($pages > 1) && ($_SESSION['view_script'])) { foreach ($page_data['up'] as $page=>$offset) { if ($offset === '...') { echo '... '; } else { - ?> - <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&sort_type=<?php echo $GLOBALS['view']->sort_type; ?>&offset=<?php echo $offset; ?>&keep_view=true"><?php echo $page; ?></a> - <?php + echo Ajax::text('?action=page&start=' . $offset,$page,'browse_page_' . $page,'','list-header'); } // end else } // end foreach up /* $counter = 1; $offset_pages = 0; while ($counter <= $pages) { - if ($GLOBALS['view']->offset == $offset_pages) { ?> + if ($start == $offset_pages) { ?> <?php } else { ?> <?php - } // end if ($GLOBALS['view']->offset == $offset_pages) and else - $offset_pages += $GLOBALS['view']->offset_limit; + } // end if ($start == $offset_pages) and else + $offset_pages += $limit; $counter++; } // end while ($counter <= $pages) */ ?> </td> <td valign="top"> - <a class="list-header" href="<?php echo $script; ?>?<?php echo $action; ?>&offset=<?php echo $next_offset; ?>&keep_view=true">[<?php echo _('Next'); ?>]</a> + <?php echo Ajax::text('?action=page&start=' . $next_offset,'[' . _('Next') . ']','browse_next','','list-header'); ?> </td> </tr> </table> <?php -} // if (($pages > 1) && ($_SESSION['view_script'])) +} // if stuff ?> diff --git a/templates/show_songs.inc.php b/templates/show_songs.inc.php index 4f2e1e9f..ab42637e 100644 --- a/templates/show_songs.inc.php +++ b/templates/show_songs.inc.php @@ -27,7 +27,7 @@ $ajax_url = Config::get('ajax_url'); <table class="tabledata" cellspacing="0" cellpadding="0"> <tr class="table-header" align="center"> <td colspan="12"> - <?php //require Config::get('prefix') . '/templates/list_header.inc.php'; ?> + <?php require Config::get('prefix') . '/templates/list_header.inc.php'; ?> </td> </tr> <tr class="table-header"> diff --git a/themes/classic/templates/default.css b/themes/classic/templates/default.css index c4586855..e0924543 100644 --- a/themes/classic/templates/default.css +++ b/themes/classic/templates/default.css @@ -430,6 +430,7 @@ span.five-stars:hover { width: 80px; } /************************************************/ .list-header { text-decoration: none; + cursor:pointer; } .list-header:hover { color:#071fd4; |