From c14e786dd14c8b4ff6a9f8639a445b08678db0b7 Mon Sep 17 00:00:00 2001 From: Markus Klein <klein.t3@mfc-linz.at> Date: Thu, 8 May 2014 20:07:13 +0200 Subject: [PATCH] [BUGFIX] List module pagination broken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A wrong formula is used to calculate the pointer for the pages. This patch also introduces a central function for calculating the pointer to a page. Resolves: #55320 Releases: 6.2 Change-Id: Ia4eec61f4f87b52d0d5e940e542998f9f82aa140 Reviewed-on: https://review.typo3.org/29949 Reviewed-by: Marcin SÄ…gol Tested-by: Marcin SÄ…gol Tested-by: Tymoteusz Motylewski Reviewed-by: Wouter Wolters Tested-by: Wouter Wolters --- .../Classes/RecordList/DatabaseRecordList.php | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php index 3d47fe3f15ff..de0a9bf9e532 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php @@ -901,6 +901,16 @@ class DatabaseRecordList extends \TYPO3\CMS\Recordlist\RecordList\AbstractDataba return $this->addelement(1, $icon, $theData, ' class="c-headLine"', ''); } + /** + * Get pointer for first element on the page + * + * @param int $page Page number starting with 1 + * @return int Pointer to first element on the page (starting with 0) + */ + protected function getPointerForPage($page) { + return ($page - 1) * $this->iLimit; + } + /** * Creates a page browser for tables with many records * @@ -913,33 +923,27 @@ class DatabaseRecordList extends \TYPO3\CMS\Recordlist\RecordList\AbstractDataba $returnContent = ''; // Show page selector if not all records fit into one page if ($totalPages > 1) { - $first = ($previous = ($next = ($last = ($reload = '')))); $listURL = $this->listURL('', $this->table); // 1 = first page - $currentPage = floor(($this->firstElementNumber + 1) / $this->iLimit) + 1; + // 0 = first element + $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1; // Compile first, previous, next, last and refresh buttons if ($currentPage > 1) { $labelFirst = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:first'); - $first = '<a href="' . $listURL . '&pointer=0">' . IconUtility::getSpriteIcon('actions-view-paging-first', array('title' => $labelFirst)) . '</a>'; - } else { - $first = IconUtility::getSpriteIcon('actions-view-paging-first-disabled'); - } - if ($currentPage - 1 > 0) { $labelPrevious = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:previous'); - $previous = '<a href="' . $listURL . '&pointer=' . ($currentPage - 2) * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-previous', array('title' => $labelPrevious)) . '</a>'; + $first = '<a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '">' . IconUtility::getSpriteIcon('actions-view-paging-first', array('title' => $labelFirst)) . '</a>'; + $previous = '<a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '">' . IconUtility::getSpriteIcon('actions-view-paging-previous', array('title' => $labelPrevious)) . '</a>'; } else { + $first = IconUtility::getSpriteIcon('actions-view-paging-first-disabled'); $previous = IconUtility::getSpriteIcon('actions-view-paging-previous-disabled'); } - if ($currentPage + 1 <= $totalPages) { + if ($currentPage < $totalPages) { $labelNext = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:next'); - $next = '<a href="' . $listURL . '&pointer=' . $currentPage * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-next', array('title' => $labelNext)) . '</a>'; - } else { - $next = IconUtility::getSpriteIcon('actions-view-paging-next-disabled'); - } - if ($currentPage != $totalPages) { $labelLast = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:last'); - $last = '<a href="' . $listURL . '&pointer=' . ($totalPages - 1) * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-last', array('title' => $labelLast)) . '</a>'; + $next = '<a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '">' . IconUtility::getSpriteIcon('actions-view-paging-next', array('title' => $labelNext)) . '</a>'; + $last = '<a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '">' . IconUtility::getSpriteIcon('actions-view-paging-last', array('title' => $labelLast)) . '</a>'; } else { + $next = IconUtility::getSpriteIcon('actions-view-paging-next-disabled'); $last = IconUtility::getSpriteIcon('actions-view-paging-last-disabled'); } $reload = '<a href="#" onclick="document.dblistForm.action=\'' . $listURL . '&pointer=\'+calculatePointer(document.getElementById(\'jumpPage-' . $renderPart . '\').value); document.dblistForm.submit(); return true;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>'; -- GitLab