Sliding.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Paginator
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Paginator_ScrollingStyle_Interface
  23. */
  24. require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
  25. /**
  26. * A Yahoo! Search-like scrolling style. The cursor will advance to
  27. * the middle of the range, then remain there until the user reaches
  28. * the end of the page set, at which point it will continue on to
  29. * the end of the range and the last page in the set.
  30. *
  31. * @link http://search.yahoo.com/search?p=Zend+Framework
  32. * @category Zend
  33. * @package Zend_Paginator
  34. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Paginator_ScrollingStyle_Sliding implements Zend_Paginator_ScrollingStyle_Interface
  38. {
  39. /**
  40. * Returns an array of "local" pages given a page number and range.
  41. *
  42. * @param Zend_Paginator $paginator
  43. * @param integer $pageRange (Optional) Page range
  44. * @return array
  45. */
  46. public function getPages(Zend_Paginator $paginator, $pageRange = null)
  47. {
  48. if ($pageRange === null) {
  49. $pageRange = $paginator->getPageRange();
  50. }
  51. $pageNumber = $paginator->getCurrentPageNumber();
  52. $pageCount = count($paginator);
  53. if ($pageRange > $pageCount) {
  54. $pageRange = $pageCount;
  55. }
  56. $delta = ceil($pageRange / 2);
  57. if ($pageNumber - $delta > $pageCount - $pageRange) {
  58. $lowerBound = $pageCount - $pageRange + 1;
  59. $upperBound = $pageCount;
  60. } else {
  61. if ($pageNumber - $delta < 0) {
  62. $delta = $pageNumber;
  63. }
  64. $offset = $pageNumber - $delta;
  65. $lowerBound = $offset + 1;
  66. $upperBound = $offset + $pageRange;
  67. }
  68. return $paginator->getPagesInRange($lowerBound, $upperBound);
  69. }
  70. }