Feature #34944

Paginate viewhelper should be possible to handle non-query-result objects

Added by most wanted about 8 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
Start date:
2012-03-16
Due date:
% Done:

100%

PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

Bildschirmfoto 2015-09-11 um 13.59.32.png View (89.4 KB) Julian Stock, 2015-09-11 13:59


Related issues

Related to TYPO3.Fluid - Feature #11740: Paginate viewhelper should be possible to handle non-query-result objects Closed 2010-12-27

Associated revisions

Revision ec9899d6 (diff)
Added by Tom Ruether over 5 years ago

[FEATURE] Paginate should handle non-query-result objects

Sometimes it is necessary to use an object storage or
an array instead of a query result.

Resolves: #34944
Releases: master
Change-Id: Ibbfbb30f005f9a21d4f59e7db1d3d0c7046b6a51
Reviewed-on: http://review.typo3.org/25687
Reviewed-by: Anja Leichsenring <>
Tested-by: Anja Leichsenring <>
Reviewed-by: Christian Kuhn <>
Tested-by: Christian Kuhn <>

History

#1 Updated by most wanted about 8 years ago

--- quote ---

Hello,

sometimes it is necessary to use an object storage or an array instead of an query result. If this is the case, it is not possible to use the default paginate viewhelper anymore, cause it is requiering a Tx_Extbase_Persistence_QueryResultInterface.

I've copied the widget and changed it to work with array. This is my indexAction of PaginateController:

public function indexAction($currentPage = 1) {
// set current page
$this->currentPage = (integer)$currentPage;
if ($this->currentPage < 1) {
$this->currentPage = 1;
} elseif ($this->currentPage > $this->numberOfPages) {
$this->currentPage = $this->numberOfPages;
}
$i = 0;
$itemsPerPage = (integer)$this->configuration['itemsPerPage'];
$modifiedObjects = array();
$indexMin = $itemsPerPage * ($this->currentPage - 1);
$indexMax = $itemsPerPage * $this->currentPage - 1;
foreach ($this->objects as $object) {
if ($i >= $indexMin && $i <= $indexMax ) {
$modifiedObjects[] = $object;
}
$i++;
}
$this->view->assign('contentArguments', array(
$this->widgetConfiguration['as'] => $modifiedObjects
));
$this->view->assign('configuration', $this->configuration);
$this->view->assign('pagination', $this->buildPagination());
}

Of cause you would have to remove the requirement of Tx_Extbase_Persistence_QueryResultInterface in PaginateViewHelper (Line 76 and 71) and PaginateController (Line 34) too.

This example is for arrays only, but if you make a check of the objecttype you can consolidate the support of queryResults (current) and arrays (this code example).

And it is relatively less work.

--- /quote ---

#2 Updated by Ingo Pfennigstorf over 7 years ago

  • Category set to 964
  • Status changed from New to Accepted
  • Target version set to 6.1.0

#3 Updated by Ingo Pfennigstorf over 7 years ago

  • Target version changed from 6.1.0 to 1910

#4 Updated by Max Messing over 7 years ago


            // Modified to let it work with non query result interfaces
            if(is_a($this->objects, 'Tx_Extbase_Persistence_QueryResultInterface')){
                $query = $this->objects->getQuery();
                $query->setLimit($itemsPerPage);
                if ($this->currentPage > 1) {
                    $query->setOffset((integer)($itemsPerPage * ($this->currentPage - 1)));
                }
                $modifiedObjects = $query->execute();
            }else{
                $offset = 0;
                if ($this->currentPage > 1) {
                    $offset = ((integer)($itemsPerPage * ($this->currentPage - 1)));
                }
                $modifiedObjects = array_slice($this->objects->toArray(), $offset, (integer)$this->configuration['itemsPerPage']);
            }

#5 Updated by Anja Leichsenring over 7 years ago

  • Project changed from Extbase MVC Framework to Fluid
  • Category changed from 964 to Fluid: Widgets
  • Target version deleted (1910)

#6 Updated by Mohamed Rebai over 6 years ago

Is this feature going to be implemented or not ? I need to apply a pagination on a array!

#7 Updated by Gerrit Code Review over 6 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/25687

#8 Updated by Gerrit Code Review over 6 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/25687

#9 Updated by Gerrit Code Review over 6 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/25687

#10 Updated by Alexander Opitz over 5 years ago

  • Project changed from Fluid to TYPO3 Core
  • Category changed from Fluid: Widgets to Fluid

#11 Updated by Gerrit Code Review over 5 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#12 Updated by Gerrit Code Review over 5 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#13 Updated by Gerrit Code Review over 5 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#14 Updated by Gerrit Code Review over 5 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#15 Updated by Gerrit Code Review over 5 years ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#16 Updated by Gerrit Code Review over 5 years ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#17 Updated by Gerrit Code Review over 5 years ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#18 Updated by Gerrit Code Review over 5 years ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#19 Updated by Gerrit Code Review over 5 years ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#20 Updated by Gerrit Code Review over 5 years ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/25687

#21 Updated by Tom Ruether over 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#22 Updated by Julian Stock over 4 years ago

This problem has been solved 8 months ago and it's still not merged into the core? w00t! :D (Tried v6.2.15)

#23 Updated by Bernhard Eckl over 4 years ago

I replaced the two files, is there any cache to delete to get it to work then? I cleared all caches with no change…

#24 Updated by Tilo Baller over 4 years ago

Bernhard Eckl wrote:

I replaced the two files, is there any cache to delete to get it to work then? I cleared all caches with no change…

Clearing cache in TYPO3 Backend might not be enough, try clearing cache in Install Tool. You also might have to clear your opcode cache, if any.

#25 Updated by Riccardo De Contardi over 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF