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

Add PagerRenderer::getPageCount() #4198

Merged
merged 2 commits into from
Feb 6, 2021

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Feb 1, 2021

Description
To generate the same link as the pagination in CI3, #4188 is not enough.
I also need the $pageCount value.
I need $pager->getCurrentPageNumber() < $pager->getPageCount() - $surroundCount.

Example:

/**
 * @var \CodeIgniter\Pager\PagerRenderer $pager
 */

$surroundCount = 2;
$pager->setSurroundCount($surroundCount);
?>

<p class="pagination">
<?php if ($pager->hasPreviousPage()) : ?>
    <?php if ($pager->getPreviousPageNumber() > $surroundCount) : ?>
    <a href="<?= $pager->getFirst() ?>" data-ci-pagination-page="<?= $pager->getFirstPageNumber() ?> rel="start">
    &laquo;<?= lang('Pager.first') ?></a>
    <?php endif ?>

    <a href="<?= $pager->getPreviousPage() ?>" data-ci-pagination-page="<?= $pager->getPreviousPageNumber() ?>" rel="prev">&lt;</a>
<?php endif ?>

<?php foreach ($pager->links() as $link) : ?>
<?php if ($link['active']) : ?>
    <strong><?= $link['title'] ?></strong>
<?php else : ?>
    <a href="<?= $link['uri'] ?>" data-ci-pagination-page="<?= $link['title'] ?>">
        <?= $link['title'] ?>
    </a>
<?php endif ?>
<?php endforeach ?>

<?php if ($pager->hasNextPage()) : ?>
    <a href="<?= $pager->getNextPage() ?>" data-ci-pagination-page="<?= $pager->getNextPageNumber() ?>" rel="next">&gt;</a>

    <?php if ($pager->getCurrentPageNumber() < $pager->getPageCount() - $surroundCount) : ?>
    <a href="<?= $pager->getLast() ?>" data-ci-pagination-page="<?= $pager->getLastPageNumber() ?>">
    <?= lang('Pager.last') ?>&raquo;</a>
    <?php endif ?>
<?php endif ?>
</p>

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn
Copy link
Member

michalsn commented Feb 1, 2021

I would rather stick to the Number suffix when we deal with methods that return numbers - simply for consistency.

Also, could we add a mention about all these new getters to the user guide (at the end of the page)? I don't want them to become a secret feature.

@kenjis
Copy link
Member Author

kenjis commented Feb 2, 2021

getPageCount() vs getPageCountNumber(), which is better?

@paulbalandan
Copy link
Member

getPageCount() vs getPageCountNumber(), which is better?

IMO getPageCount() is better as count already implies integer number.

@michalsn
Copy link
Member

michalsn commented Feb 4, 2021

Fair enough.

@paulbalandan
Copy link
Member

@kenjis I think it's settled. Thanks for this. While you're at it, can you send a separate doc PR for these new getters?

@paulbalandan paulbalandan merged commit 6660ce9 into codeigniter4:develop Feb 6, 2021
@kenjis kenjis deleted the add-getPageCount branch February 8, 2021 09:50
@kenjis
Copy link
Member Author

kenjis commented Feb 8, 2021

@paulbalandan Okay, I will.

@kenjis kenjis mentioned this pull request Feb 8, 2021
5 tasks
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

Successfully merging this pull request may close these issues.

4 participants