Fix #15077, #15100 - Incorrect page numbers

Fixes: #15077
Fixes: #15100
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2019-03-26 19:32:01 +01:00
commit ec2e28fa04
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
2 changed files with 28 additions and 1 deletions

View File

@ -2257,6 +2257,18 @@ class Util
return $gotopage;
} // end function
/**
* Calculate page number through position
* @param int $pos position of first item
* @param int $max_count number of items per page
* @return int $page_num
* @access public
*/
public static function getPageFromPosition($pos, $max_count) {
return floor($pos / $max_count)+1;
}
/**
* Prepare navigation for a list
*
@ -2276,6 +2288,7 @@ class Util
*
* @todo use $pos from $_url_params
*/
public static function getListNavigator(
$count, $pos, array $_url_params, $script, $frame, $max_count, $name = 'pos',
$classes = array()
@ -2333,7 +2346,7 @@ class Util
$list_navigator_html .= self::pageselector(
$name,
$max_count,
floor(($pos + 1) / $max_count) + 1,
self::getPageFromPosition($pos, $max_count),
ceil($count / $max_count)
);
$list_navigator_html .= '</form>';

View File

@ -2044,6 +2044,20 @@ class UtilTest extends PmaTestCase
);
}
/**
* Test for Util::getPageFromPosition
*
* @return void
*
* @covers PhpMyAdmin\Util::getPageFromPosition
*/
function testGetPageFromPosition() {
$this->assertEquals(Util::getPageFromPosition(0,1), 1);
$this->assertEquals(Util::getPageFromPosition(1,1), 2);
$this->assertEquals(Util::getPageFromPosition(1,2), 1);
$this->assertEquals(Util::getPageFromPosition(1,6), 1);
}
/**
* Test for Util::linkOrButton
*