Sliding.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ Aw2GFbrRPr5q7etq1wC6Bd0Gqhfw2XXpQ3dGbAV5kx0=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * sliding paginator scrolling style
  14. */
  15. namespace Cube\Paginator\ScrollingStyle;
  16. use Cube\Paginator;
  17. class Sliding implements ScrollingStyleInterface
  18. {
  19. /**
  20. *
  21. * returns an array of pages in range
  22. *
  23. * @param \Cube\Paginator $paginator
  24. * @param integer $pageRange (Optional) Page range
  25. * @return array
  26. */
  27. public function getPages(Paginator $paginator, $pageRange = null)
  28. {
  29. if ($pageRange === null) {
  30. $pageRange = $paginator->getPageRange();
  31. }
  32. $pageNumber = $paginator->getCurrentPageNumber();
  33. $pageCount = count($paginator);
  34. if ($pageRange > $pageCount) {
  35. $pageRange = $pageCount;
  36. }
  37. $delta = ceil($pageRange / 2);
  38. if ($pageNumber - $delta > $pageCount - $pageRange) {
  39. $min = $pageCount - $pageRange + 1;
  40. $max = $pageCount;
  41. }
  42. else {
  43. if ($pageNumber - $delta < 0) {
  44. $delta = $pageNumber;
  45. }
  46. $offset = $pageNumber - $delta;
  47. $min = $offset + 1;
  48. $max = $offset + $pageRange;
  49. }
  50. return $paginator->getPagesInRange($min, $max);
  51. }
  52. }