123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace App\Widget\Pagination;
- use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
- use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
- use Illuminate\Pagination\UrlWindow;
- use Illuminate\Pagination\UrlWindowPresenterTrait;
- class Pagination implements PresenterContract
- {
- use UrlWindowPresenterTrait;
- protected $paginationWrapper = '<ul class="icon_paging_tow">%s %s %s</ul>';
- protected $disabledPageWrapper = '<li class="uk-disabled"><span>%s</span></li>';
- protected $activePageWrapper = '<li class=""><span>%s</span></li>';
- protected $previousButtonText = '<i class=""></i>';
- protected $nextButtonText = '<i class="uk-icon-angle-double-right"></i>';
- protected $availablePageWrapper = '<li><a href="%s">%s</a></li>';
- protected $dotsText = '...';
- protected $paginator;
- protected $window;
- public function run()
- {
- return $this;
- }
- public function create( PaginatorContract $paginator, UrlWindow $window = null )
- {
- $this->paginator = $paginator;
- $this->window = is_null( $window ) ? UrlWindow::make( $paginator ) : $window->get();
- return $this;
- }
- public function simpleCreate( PaginatorContract $paginator )
- {
- $this->paginator = $paginator;
- return $this;
- }
- public function hasPages()
- {
- return $this->paginator->hasPages();
- }
- public function render()
- {
- if ( $this->hasPages() ) {
- return sprintf(
- $this->getPaginationWrapperHTML(),
- $this->getPreviousButton(),
- $this->getLinks(),
- $this->getNextButton()
- );
- }
- return '';
- }
- protected function getAvailablePageWrapper( $url, $page )
- {
- return sprintf( $this->getAvailablePageWrapperHTML(), $url, $page );
- }
- protected function getDisabledTextWrapper( $text )
- {
- return sprintf( $this->getDisabledPageWrapperHTML(), $text );
- }
- protected function getActivePageWrapper( $text )
- {
- return sprintf( $this->getActivePageWrapperHTML(), $text );
- }
- protected function getDots()
- {
- return $this->getDisabledTextWrapper( $this->getDotsText() );
- }
- protected function currentPage()
- {
- return $this->paginator->currentPage();
- }
- protected function lastPage()
- {
- return $this->paginator->lastPage();
- }
- protected function getPageLinkWrapper( $url, $page )
- {
- if ( $page == $this->paginator->currentPage() ) {
- return $this->getActivePageWrapper( $page );
- }
- return $this->getAvailablePageWrapper( $url, $page );
- }
- protected function getPreviousButton()
- {
- if ( $this->paginator->currentPage() <= 1 ) {
- return $this->getDisabledTextWrapper( $this->getPreviousButtonText() );
- }
- $url = $this->paginator->url(
- $this->paginator->currentPage() - 1
- );
- return $this->getPageLinkWrapper( $url, $this->getPreviousButtonText() );
- }
- protected function getNextButton()
- {
- if ( !$this->paginator->hasMorePages() ) {
- return $this->getDisabledTextWrapper( $this->getNextButtonText() );
- }
- $url = $this->paginator->url( $this->paginator->currentPage() + 1 );
- return $this->getPageLinkWrapper( $url, $this->getNextButtonText() );
- }
- protected function getAvailablePageWrapperHTML()
- {
- return $this->availablePageWrapper;
- }
- protected function getActivePageWrapperHTML()
- {
- return $this->activePageWrapper;
- }
- protected function getDisabledPageWrapperHTML()
- {
- return $this->disabledPageWrapper;
- }
- protected function getPreviousButtonText()
- {
- return $this->previousButtonText;
- }
- protected function getNextButtonText()
- {
- return $this->nextButtonText;
- }
- protected function getDotsText()
- {
- return $this->dotsText;
- }
- protected function getPaginationWrapperHTML()
- {
- return $this->paginationWrapper;
- }
- }
|