PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_Pager » Bug #4602

Range is not the correct width if maxpages is set.

Details

Submitted2005-06-16 04:52 UTC
Fromssharkey at linuxunlimited dot com
Assignedquipo
StatusClosed
PackageDB_Pager
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2005-06-16 04:52 UTC] ssharkey at linuxunlimited dot com

Description:
------------
Problem:

The current implementation of DB-Pager does not properly return a full data array if the current page is less than $maxpages from either the top or bottom of the range. For instance, if you have 100 pages, and set $maxpages to 10, you should have 10 pages. But if you are currently on page 3, the range only displays from 1-7, instead of 1 to 10. The same thing happens at the upper end, if you are currently on 97, it will only show 93-100. The attached patch corrects the behaviour, by first looking to see if the number of pages is greater than the requested maxpages. IF so, the range is set 1-NumPages. If not, we look to see if we are within $maxpages of either the top or the bottom, and adjust the min/max pages to give the full requested number of pages.

Reproduce code:
---------------
--- Pager.php 2005-06-15 22:23:48.614014096 -0400
+++ Pager-patched.php 2005-06-16 00:36:02.837828736 -0400
@@ -211,6 +211,23 @@
if ($maxpage > $data['numpages']) {
$maxpage = $data['numpages'];
}
+
+ // SAS mod - Adjust min/maxpage if numpages is too
+ // small, or if we are near the top or bottom of range...
+ if ($data['numpages'] < $maxpages) {
+ $minpage = 1;
+ $maxpage = $data['numpages'];
+ } else {
+ // if we're at the top of the range, move minpage down...
+ if ($data['lastpage'] - $minpage < $maxpages) {
+ $minpage = $data['lastpage'] - $maxpages + 1;
+ }
+ // if we're at the bottom of the range, move maxpage up...
+ if ($maxpage < $maxpages) {
+ $maxpage = $maxpages;
+ }
+ } // end SAS mod
+
foreach (range($minpage, $maxpage) as $page) {
$tmp[$page] = $data['pages'][$page];
}

Expected result:
----------------
The resulting pager always displays $maxpages pages, unless the total number of pages is less, in which case it displays 1 to the total number of pages.