Issue Feature Closed

#102196SimplePagination: total number of items

Philipp Kitzberger 10/18/23, 12:01 updated 09/29/26, 19:28

Description

It seems impossible to me to determine the total number of items from the current implementation of SimplePagination.
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

  1. Georg Ringer commented and changed status New Accepted 06/07/24, 15:19

    what about adding a public method which returns getTotalAmountOfItems?

  2. Georg Ringer changed Complexity easy 06/07/24, 15:20

  3. Georg Ringer changed Complexity easy Sprint Focus On Location Sprint 06/07/24, 16:09

  4. Marc Willmann commented and changed attached TER-example.png status Accepted Needs Feedback assigned to Philipp Kitzberger 08/01/24, 19:36

    I’m not sure if I understand the problem correctly. The PaginatorInterface indeed lacks the named method; but the abstract implementation AbstractPaginator has exactly this method

        abstract protected function getTotalAmountOfItems(): int;

    and as your examples ArrayPaginator and QueryResultPaginator extend the AbstractPaginator (and not implement the PaginatorInterface on its own) they both have implemented the named method too (in different ways of course, but that’s not an issue), e.g. the QueryResultPaginator

        protected 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.

    TER-example.png

    Do you have a use-/test-case for your issue or does this already solve your problem?

  5. 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 beforementioned getTotalAmountOfItems() to the SimplePagination and/or the PaginationInterface.

  6. 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. The PaginatorInterface indeed lacks the named method; but the abstract implementation AbstractPaginator has exactly this method
    >
    > […]
    >
    > and as your examples ArrayPaginator and QueryResultPaginator extend the AbstractPaginator (and not implement the PaginatorInterface on its own) they both have implemented the named method too (in different ways of course, but that’s not an issue), e.g. the QueryResultPaginator

    The 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.

  7. 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.

  8. Georg Ringer changed Sprint Focus On Location Sprint 08/06/26, 15:51

  9. Georg Ringer commented and changed status Needs Feedback Closed 09/29/26, 19:28

    closing in favor of #106764