Project

General

Profile

Actions

Feature #102196

open

SimplePagination: total number of items

Added by Philipp Kitzberger about 1 year ago. Updated 3 months ago.

Status:
Needs Feedback
Priority:
Should have
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2023-10-18
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:
On Location Sprint

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


Files

TER-example.png (24.9 KB) TER-example.png Marc Willmann, 2024-08-01 19:35
Actions #1

Updated by Georg Ringer 5 months ago

  • Status changed from New to Accepted

what about adding a public method which returns getTotalAmountOfItems?

Actions #2

Updated by Georg Ringer 5 months ago

  • Complexity set to easy
Actions #3

Updated by Georg Ringer 5 months ago

  • Complexity deleted (easy)
  • Sprint Focus set to On Location Sprint
Actions #4

Updated by Marc Willmann 3 months ago

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.

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

Actions #5

Updated by Philipp Kitzberger 3 months ago ยท Edited

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.

Actions

Also available in: Atom PDF