#102196SimplePagination: total number of items
Description
There’s all sort of getters that use the objects paginator (
ArrayPaginator or QueryResultPaginator) to ask for its properties:
getPreviousPageNumber()calling->paginator->getCurrentPageNumber()and->paginator->getNumberOfPages()
getNextPageNumber()calling->paginator->getCurrentPageNumber()and->paginator->getNumberOfPages()
getLastPageNumber()calling->paginator->getNumberOfPages()
getStartRecordNumber()calling->paginator->getCurrentPageNumber()and->paginator->getNumberOfPages()
getEndRecordNumber()calling->paginator->getCurrentPageNumber()and->paginator->getNumberOfPages()
But no method to get the total number of records. So displaying a text like this is not possible:
> Here’s 10 out of a total of 321 records
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Files 1
History 9
-
Georg Ringer commented and changed status
NewAccepted 06/07/24, 15:19 -
Georg Ringer changed Complexity easy 06/07/24, 15:20
-
Georg Ringer changed Complexity
easySprint Focus On Location Sprint 06/07/24, 16:09 -
Marc Willmann commented and changed attached TER-example.png status
AcceptedNeeds Feedback assigned to Philipp Kitzberger 08/01/24, 19:36I’m not sure if I understand the problem correctly. The
PaginatorInterfaceindeed lacks the named method; but the abstract implementationAbstractPaginatorhas exactly this methodabstract protected function getTotalAmountOfItems(): int;and as your examples
ArrayPaginatorandQueryResultPaginatorextend the AbstractPaginator (and not implement thePaginatorInterfaceon its own) they both have implemented the named method too (in different ways of course, but that’s not an issue), e.g. theQueryResultPaginatorprotected function getTotalAmountOfItems(): int { return count($this->queryResult); }The Extension TER-list is using the
SinglePagination, which lacks this method. But there is the list of items already present itself, so you can easily count in this case{extensions}(or any other array storing your data) to get the number needed.Do you have a use-/test-case for your issue or does this already solve your problem?
-
Philipp Kitzberger commented 08/05/24, 07:53
> The Extension TER-list is using the SinglePagination, which lacks this method. But there is the list of items already present itself, so you can easily count in this case {extensions} (or any other array storing your data) to get the number needed.
I don’t know this TER-list extension. But you mean SimplePagination, right? And with the list of items you mean the Paginator object that is separate from the Pagination object? Sure, one could use the Paginator objects
getTotalAmountOfItems()method.But then why separate the logic into Pagination and Paginator at all when I have to use both in order to render the “usual scenario” as depict in your screenshot? Imagine a partial used to render the Pagination would always have both objects present. Thus I vote for adding either
getPaginator()or the beforementionedgetTotalAmountOfItems()to the SimplePagination and/or thePaginationInterface. -
Philipp Lüdtke commented 03/21/25, 14:51
Marc Willmann wrote in #note-4:
> I’m not sure if I understand the problem correctly. ThePaginatorInterfaceindeed lacks the named method; but the abstract implementationAbstractPaginatorhas exactly this method
>
> […]
>
> and as your examplesArrayPaginatorandQueryResultPaginatorextend the AbstractPaginator (and not implement thePaginatorInterfaceon its own) they both have implemented the named method too (in different ways of course, but that’s not an issue), e.g. theQueryResultPaginatorThe method is not public though and therefore not usable for me when im using either the QueryResultPaginator or ArrayPaginator. I dont understand why this is not simply a public function like the others like “getNextPageNumber” etc. too.
-
Simon Schaufelberger commented 02/13/26, 23:57
I don’t understand the use case as well. When you create a new pagination like
SimplePagination, you already pass in the paginator into the constructor and in order to create a Paginator, you need to hand over the items so you can also count the items that you pass to the Paginator, or?Adding
public function getPaginator(): PaginatorInterface;to the interface won’t help much as the Paginator doesn’t have a public method to get the items, so you can only access them in a subclass but not from outside. -
Georg Ringer changed Sprint Focus
On Location Sprint08/06/26, 15:51 -
Georg Ringer commented and changed status
Needs FeedbackClosed 09/29/26, 19:28closing in favor of #106764
what about adding a public method which returns
getTotalAmountOfItems?