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

feat: add methods to get page numbers in PagerRenderer #4188

Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jan 30, 2021

Description
Supersedes #4141

Add methods to get page numbers in PagerRenderer.
To generate Pager HTML that is the same as CI3's.

  • getFirstPageNumber()
  • getCurrentPageNumber()
  • getLastPageNumber()
  • getPreviousPageNumber()
  • getNextPageNumber()

The template would be like this:

<?php if ($pager->hasPreviousPage()) : ?>
<a href="<?= $pager->getFirst() ?>" data-ci-pagination-page="<?= $pager->getFirstPageNumber() ?>" rel="start">&laquo;First</a>
<a href="<?= $pager->getPreviousPage() ?>" data-ci-pagination-page="<?= $pager->getPreviousPageNumber() ?>" rel="prev">&lt;</a>
<?php endif ?>

Checklist:

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

To create the same link as the CI3 link.
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making it more sound natural? Like getFirstPageNumber, getCurrentPageNumber, getLastPageNumber. Then add another for getPreviousPageNumber.

Or better yet, remove the Number? getFirstPage, getLastPage etc.

@michalsn
Copy link
Member

Or better yet, remove the Number? getFirstPage, getLastPage etc.

We already have methods in this convention and they all return an URL, so it might be confusing for users. But your idea of having getFirstPageNumber, getCurrentPageNumber, getLastPageNumber sounds better to me - more natural.

@kenjis One thing I don't like is this:

$pager->getPageNumberCurrent() - 1

We should add a method getPreviousPageNumber() (and getNextPageNumber()) that will make calculations for us. Of course, we still can have getCurrentPageNumber() method.

@kenjis kenjis changed the title feat: add getters for page number in PagerRenderer feat: add methods to get page numbers in PagerRenderer Jan 30, 2021
@kenjis
Copy link
Member Author

kenjis commented Jan 30, 2021

I changed the method names, and added getPreviousPageNumber() and getNextPageNumber().

tests/system/Pager/PagerRendererTest.php Outdated Show resolved Hide resolved
tests/system/Pager/PagerRendererTest.php Outdated Show resolved Hide resolved
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think this is a better solution than the magic getter. Please implement @paulbalandan 's assertion changes, then I think we're set.

kenjis and others added 2 commits January 31, 2021 06:58
Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>
Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>
@kenjis
Copy link
Member Author

kenjis commented Jan 30, 2021

@MGatner Done! Thanks for all.

@MGatner MGatner merged commit 3685755 into codeigniter4:develop Jan 30, 2021
@kenjis kenjis deleted the feat-PagerRenderer-property-accessor-v2 branch January 30, 2021 23:01
@kenjis kenjis mentioned this pull request Feb 1, 2021
5 tasks
@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.

None yet

4 participants