whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

What about LimitedPagerfanta #244

Open insekticid opened 6 years ago

insekticid commented 6 years ago

Sometimes you do not want to show all pages based on results count.

<?php

declare(strict_types=1);

namespace App\Util;

use Pagerfanta\Pagerfanta;
use function min;

class LimitedPagerfanta extends Pagerfanta
{
    /**
     * @var int
     */
    private $limitedPageNumber;

    public function setLimitedPageNumber(int $limitedPageNumber) : LimitedPagerfanta
    {
        $this->limitedPageNumber = $limitedPageNumber;
        return $this;
    }

    public function getNbResults() : int
    {
        $results = parent::getNbResults();

        return (int) min($results, $this->limitedPageNumber * $this->getMaxPerPage());
    }
}
Koc commented 5 years ago

Sometimes it needed, but it is better to decorate adapter.

sampart commented 5 years ago

Thanks for your input, @Koc. Do you have any code examples of how you've done this?

Koc commented 5 years ago

@sampart see #261

sampart commented 5 years ago

Thanks, @Koc.