Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about LimitedPagerfanta #244

Open
insekticid opened this issue Mar 10, 2018 · 4 comments
Open

What about LimitedPagerfanta #244

insekticid opened this issue Mar 10, 2018 · 4 comments

Comments

@insekticid
Copy link

insekticid commented Mar 10, 2018

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
Copy link

Koc commented Oct 30, 2018

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

@sampart
Copy link
Collaborator

sampart commented Oct 30, 2018

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

@Koc
Copy link

Koc commented Oct 31, 2018

@sampart see #261

@sampart
Copy link
Collaborator

sampart commented Oct 31, 2018

Thanks, @Koc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants