From dcfb88b2e8e08083f092fe751b543e6546cbcdd2 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 10 Dec 2008 01:03:09 +0000 Subject: [PATCH] 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 --- core/model/DataObjectSet.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/model/DataObjectSet.php b/core/model/DataObjectSet.php index 5f169a7ed..81dce01ea 100644 --- a/core/model/DataObjectSet.php +++ b/core/model/DataObjectSet.php @@ -292,21 +292,24 @@ class DataObjectSet extends ViewableData implements IteratorAggregate { * <% end_if %> * * - * @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;