BUGFIX Improved DataObjectSet->PaginationSummary() to show full context (instead of halved) when on first or last page

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68039 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-12-10 01:03:09 +00:00 committed by Sam Minnee
parent 401a6b8e70
commit dcfb88b2e8

View File

@ -292,21 +292,24 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
* <% end_if %>
* </code>
*
* @param integer $context Number of pages to display "around" the current page
* @param integer $context Number of pages to display "around" the current page. Number should be even,
* because its halved to either side of the current page.
* @return DataObjectSet
*/
public function PaginationSummary($context = 4) {
$ret = new DataObjectSet();
if (!$context) return $this->Pages();
// convert number of pages to even number for offset calculation
if($context % 2) $context--;
if($context % 2) $context--;
// find out the offset
$offset = floor($context/2);
$current = $this->CurrentPage();
$totalPages = $this->TotalPages();
// if the first or last page is shown, use all content on one side (either left or right of current page)
// otherwise half the number for usage "around" the current page
$offset = ($current == 1 || $current == $totalPages) ? $context : floor($context/2);
$leftOffset = $current - ($offset);
if($leftOffset < 1) $leftOffset = 1;
if($leftOffset + $context > $totalPages) $leftOffset = $totalPages - $context;