Feature: #102194 - Introduce QueryBuilderPaginator
See forge#102194
Description
A new
\TYPO3\ is introduced to
enable pagination of
Query instances.
The paginator implements the existing
Paginator and integrates
seamlessly with the existing
Simple and
Sliding 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
Query instance. This approach correctly
handles advanced queries involving UNION, nested CTEs, window functions, and
grouping.
Note
The
Query does
not handle language overlays. Applying overlays to the result set can
lead to unexpected item count differences between pages when some records
are hidden after overlay processing. Use
\Query or
Array when language
overlay handling is required.
The paginator also takes full control over LIMIT and OFFSET
and does not respect any existing limit or offset constraints on the
passed
Query instance.
Impact
A new
Query is
available to paginate
Query result sets using
the TYPO3 pagination API.
Example
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();