Pagination.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Widget\Pagination;
  3. use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
  4. use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
  5. use Illuminate\Pagination\UrlWindow;
  6. use Illuminate\Pagination\UrlWindowPresenterTrait;
  7. class Pagination implements PresenterContract
  8. {
  9. use UrlWindowPresenterTrait;
  10. protected $paginationWrapper = '<ul class="icon_paging_tow">%s %s %s</ul>';
  11. protected $disabledPageWrapper = '<li class="uk-disabled"><span>%s</span></li>';
  12. protected $activePageWrapper = '<li class=""><span>%s</span></li>';
  13. protected $previousButtonText = '<i class=""></i>';
  14. protected $nextButtonText = '<i class="uk-icon-angle-double-right"></i>';
  15. protected $availablePageWrapper = '<li><a href="%s">%s</a></li>';
  16. protected $dotsText = '...';
  17. protected $paginator;
  18. protected $window;
  19. public function run()
  20. {
  21. return $this;
  22. }
  23. public function create( PaginatorContract $paginator, UrlWindow $window = null )
  24. {
  25. $this->paginator = $paginator;
  26. $this->window = is_null( $window ) ? UrlWindow::make( $paginator ) : $window->get();
  27. return $this;
  28. }
  29. public function simpleCreate( PaginatorContract $paginator )
  30. {
  31. $this->paginator = $paginator;
  32. return $this;
  33. }
  34. public function hasPages()
  35. {
  36. return $this->paginator->hasPages();
  37. }
  38. public function render()
  39. {
  40. if ( $this->hasPages() ) {
  41. return sprintf(
  42. $this->getPaginationWrapperHTML(),
  43. $this->getPreviousButton(),
  44. $this->getLinks(),
  45. $this->getNextButton()
  46. );
  47. }
  48. return '';
  49. }
  50. protected function getAvailablePageWrapper( $url, $page )
  51. {
  52. return sprintf( $this->getAvailablePageWrapperHTML(), $url, $page );
  53. }
  54. protected function getDisabledTextWrapper( $text )
  55. {
  56. return sprintf( $this->getDisabledPageWrapperHTML(), $text );
  57. }
  58. protected function getActivePageWrapper( $text )
  59. {
  60. return sprintf( $this->getActivePageWrapperHTML(), $text );
  61. }
  62. protected function getDots()
  63. {
  64. return $this->getDisabledTextWrapper( $this->getDotsText() );
  65. }
  66. protected function currentPage()
  67. {
  68. return $this->paginator->currentPage();
  69. }
  70. protected function lastPage()
  71. {
  72. return $this->paginator->lastPage();
  73. }
  74. protected function getPageLinkWrapper( $url, $page )
  75. {
  76. if ( $page == $this->paginator->currentPage() ) {
  77. return $this->getActivePageWrapper( $page );
  78. }
  79. return $this->getAvailablePageWrapper( $url, $page );
  80. }
  81. protected function getPreviousButton()
  82. {
  83. if ( $this->paginator->currentPage() <= 1 ) {
  84. return $this->getDisabledTextWrapper( $this->getPreviousButtonText() );
  85. }
  86. $url = $this->paginator->url(
  87. $this->paginator->currentPage() - 1
  88. );
  89. return $this->getPageLinkWrapper( $url, $this->getPreviousButtonText() );
  90. }
  91. protected function getNextButton()
  92. {
  93. if ( !$this->paginator->hasMorePages() ) {
  94. return $this->getDisabledTextWrapper( $this->getNextButtonText() );
  95. }
  96. $url = $this->paginator->url( $this->paginator->currentPage() + 1 );
  97. return $this->getPageLinkWrapper( $url, $this->getNextButtonText() );
  98. }
  99. protected function getAvailablePageWrapperHTML()
  100. {
  101. return $this->availablePageWrapper;
  102. }
  103. protected function getActivePageWrapperHTML()
  104. {
  105. return $this->activePageWrapper;
  106. }
  107. protected function getDisabledPageWrapperHTML()
  108. {
  109. return $this->disabledPageWrapper;
  110. }
  111. protected function getPreviousButtonText()
  112. {
  113. return $this->previousButtonText;
  114. }
  115. protected function getNextButtonText()
  116. {
  117. return $this->nextButtonText;
  118. }
  119. protected function getDotsText()
  120. {
  121. return $this->dotsText;
  122. }
  123. protected function getPaginationWrapperHTML()
  124. {
  125. return $this->paginationWrapper;
  126. }
  127. }