Paginator.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. if(!defined('APP_KEY')) { exit('Access Denied'); }
  3. class Helper_Paginator extends Suco_Helper_Paginator
  4. {
  5. protected $_maxPage = 250;
  6. public $nextPageCaption = '&raquo;';
  7. public $prevPageCaption = '&laquo;';
  8. public $firstPageCaption = '首页';
  9. public $lastPageCaption = '未页';
  10. public static function callback($args)
  11. {
  12. return @new self($args[0], $args[1], $args[2], $args[3]);
  13. }
  14. public function firstPage($caption = '')
  15. {
  16. if ((!$caption && $this->getCurrentPage() - $this->pageNumberLength - 1 < 1)) {
  17. return;
  18. }
  19. return '<a href="'.$this->go('first').'">'.($caption ? $caption : 1).'</a>' . ($caption ? '' : '<a>...</a>');
  20. }
  21. public function lastPage($caption = '')
  22. {
  23. if ((!$caption && $this->_currentPage > $this->getTotalPage() - $this->pageNumberLength - 1)) {
  24. return;
  25. }
  26. return ($caption ? '' : ' <a>...</a> ') . '<a href="'.$this->go('last').'">'.($caption ? $caption : $this->_totalPage).'</a>';
  27. }
  28. public function pageNumber($length = null)
  29. {
  30. if ($length) {
  31. $this->pageNumberLength = $length;
  32. } else {
  33. $length = $this->pageNumberLength;
  34. }
  35. $str = null;
  36. for ($i = $this->getCurrentPage() - $length; $i < $this->getCurrentPage() + $length + 1; $i++) {
  37. if ($i < 1 || $i > $this->getTotalPage()) continue;
  38. $str .= '<li '.($this->getCurrentPage() == $i ? ' class="active"' : '').'><a href="'.$this->go($i).'">'.$i.'</a></li> ';
  39. }
  40. return $str;
  41. }
  42. public function getFullBar()
  43. {
  44. if (!$this->getTotalRecord()) { return ''; }
  45. $st = ($this->_currentPage - 1) * $this->_pageSize + 1;
  46. $et = $this->_currentPage * $this->_pageSize;
  47. $et = $et > $this->_totalRecord ? $this->_totalRecord : $et;
  48. return <<<EOF
  49. <li>{$this->prevPage()}</li><li> {$this->firstPage()}</li> {$this->pageNumber(3)} <li>{$this->lastPage()}</li> <li>{$this->nextPage()}</li>
  50. EOF;
  51. }
  52. public function getMiniBar()
  53. {
  54. if (!$this->getTotalRecord()) { return ''; }
  55. return <<<EOF
  56. <span>共 <em>{$this->getTotalRecord()}</em> 件商品 </span>
  57. <span>{$this->getCurrentPage()}/{$this->getTotalPage()}</span> {$this->prevPage()} {$this->nextPage()}
  58. EOF;
  59. }
  60. public function getInputBox()
  61. {
  62. return <<<EOF
  63. 到 <input type="text" id="inputPage" class="page_input" value="{$this->getCurrentPage()}" size="3" name="page"> 页
  64. <input type="submit" class="page_but" value="确定">
  65. EOF;
  66. }
  67. public function go($page)
  68. {
  69. switch ($page) {
  70. case 'first': $page = 1; break;
  71. case 'last': $page = $this->getTotalPage(); break;
  72. case 'next': $page = $this->getCurrentPage() >= $this->getTotalPage() ? $this->getCurrentPage() : $this->getCurrentPage()+1;
  73. break;
  74. case 'prev':
  75. $page = $this->getCurrentPage() <= 1 ? $this->getCurrentPage() : $this->getCurrentPage()-1;
  76. break;
  77. }
  78. if ($this->getAjaxFunc()) {
  79. return 'javascript:'.$this->getAjaxFunc().'('.$page.')"';
  80. } else {
  81. return Suco_Controller_Router_Route_Abstract::decode(Suco_Application::instance()->getRouter()
  82. ->reverse('&page=' . ($page > 1 ? $page : '')));
  83. }
  84. }
  85. }