Feature: #102194 - Introduce QueryBuilderPaginator 

See forge#102194

Description 

A new \TYPO3\CMS\Core\Pagination\QueryBuilderPaginator is introduced to enable pagination of \TYPO3\CMS\Core\Database\Query\QueryBuilder instances directly.

The paginator implements the existing \TYPO3\CMS\Core\Pagination\PaginatorInterface and integrates seamlessly with the existing \TYPO3\CMS\Core\Pagination\SimplePagination and \TYPO3\CMS\Core\Pagination\SlidingWindowPagination classes.

The paginated items are fetched only once per page request by storing the result internally, avoiding double execution of the database statement.

The total item count is determined robustly using a common table expression (CTE) wrapping the passed QueryBuilder instance. This approach correctly handles advanced queries involving UNION, nested CTEs, windowing functions, or grouping.

Impact 

A new QueryBuilderPaginator is available to paginate QueryBuilder result sets using the standard TYPO3 pagination API.

Example 

EXT:my_extension/Classes/Controller/MyController.php
use TYPO3\CMS\Core\Pagination\QueryBuilderPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;

$paginator = new QueryBuilderPaginator(
    queryBuilder: $queryBuilder,
    currentPageNumber: $currentPage,
    itemsPerPage: 10,
);
$pagination = new SimplePagination($paginator);

// Retrieve the items for the current page
$items = $paginator->getPaginatedItems();
Copied!