Feature #34944

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

Added by Roland Waldner over 3 years ago. Updated 7 months ago.

Status:Resolved Start date:2012-03-16
Priority:Should have Due date:
Assigned To:- % Done:

100%

Category:Fluid Spent time: -
Target version:-
PHP Version: Sprint Focus:
Complexity:

Description


Related issues

related to TYPO3.Fluid - Feature #11740: Paginate viewhelper should be possible to handle non-quer... Closed 2010-12-27

Associated revisions

Revision ec9899d6
Added by Tom Ruether 7 months 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 Roland Waldner over 3 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 almost 3 years ago

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

#3 Updated by Ingo Pfennigstorf almost 3 years ago

  • Target version changed from 6.1.0 to 1910

#4 Updated by Max Messing over 2 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 2 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 1 year 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 1 year 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 1 year 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 1 year 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 11 months ago

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

#11 Updated by Gerrit Code Review 8 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months 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 7 months ago

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

Also available in: Atom PDF