[BUGFIX] Return empty result in pagination if page does not exist
authordkd-egerer Sascha Egerer <sascha.egerer@dkd.de>
Fri, 13 Apr 2012 14:56:41 +0000 (16:56 +0200)
committerMarc Bastian Heinrichs <heinrichs@mbh-web.de>
Fri, 13 Apr 2012 14:56:41 +0000 (16:56 +0200)
The pagination widget does currently return the content of the
latest page if the requestet page is higher than the available page.

This patch changes this behavior so that an empty result is returned
for non existing pages.

Change-Id: Iadde1951e70ef5ddfbdc9830cb3121594862f700
Fixes: #33033
Releases: master, 4.7, 1.4, 1.3

typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php

index ea6ce73..372e373 100644 (file)
@@ -68,18 +68,21 @@ class Tx_Fluid_ViewHelpers_Widget_Controller_PaginateController extends Tx_Fluid
                $this->currentPage = (integer)$currentPage;
                if ($this->currentPage < 1) {
                        $this->currentPage = 1;
-               } elseif ($this->currentPage > $this->numberOfPages) {
-                       $this->currentPage = $this->numberOfPages;
                }
 
-                       // modify query
-               $itemsPerPage = (integer)$this->configuration['itemsPerPage'];
-               $query = $this->objects->getQuery();
-               $query->setLimit($itemsPerPage);
-               if ($this->currentPage > 1) {
-                       $query->setOffset((integer)($itemsPerPage * ($this->currentPage - 1)));
+               if ($this->currentPage > $this->numberOfPages) {
+                               // set $modifiedObjects to NULL if the page does not exist
+                       $modifiedObjects = NULL;
+               } else {
+                               // modify query
+                       $itemsPerPage = (integer)$this->configuration['itemsPerPage'];
+                       $query = $this->objects->getQuery();
+                       $query->setLimit($itemsPerPage);
+                       if ($this->currentPage > 1) {
+                               $query->setOffset((integer)($itemsPerPage * ($this->currentPage - 1)));
+                       }
+                       $modifiedObjects = $query->execute();
                }
-               $modifiedObjects = $query->execute();
 
                $this->view->assign('contentArguments', array(
                        $this->widgetConfiguration['as'] => $modifiedObjects