CBasePager.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * CBasePager class file.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CBasePager is the base class for all pagers.
  12. *
  13. * It provides the calculation of page count and maintains the current page.
  14. *
  15. * @property CPagination $pages The pagination information.
  16. * @property integer $pageSize Number of items in each page.
  17. * @property integer $itemCount Total number of items.
  18. * @property integer $pageCount Number of pages.
  19. * @property integer $currentPage The zero-based index of the current page. Defaults to 0.
  20. *
  21. * @author Qiang Xue <qiang.xue@gmail.com>
  22. * @package system.web.widgets.pagers
  23. * @since 1.0
  24. */
  25. abstract class CBasePager extends CWidget
  26. {
  27. private $_pages;
  28. /**
  29. * Returns the pagination information used by this pager.
  30. * @return CPagination the pagination information
  31. */
  32. public function getPages()
  33. {
  34. if($this->_pages===null)
  35. $this->_pages=$this->createPages();
  36. return $this->_pages;
  37. }
  38. /**
  39. * Sets the pagination information used by this pager.
  40. * @param CPagination $pages the pagination information
  41. */
  42. public function setPages($pages)
  43. {
  44. $this->_pages=$pages;
  45. }
  46. /**
  47. * Creates the default pagination.
  48. * This is called by {@link getPages} when the pagination is not set before.
  49. * @return CPagination the default pagination instance.
  50. */
  51. protected function createPages()
  52. {
  53. return new CPagination;
  54. }
  55. /**
  56. * @return integer number of items in each page.
  57. * @see CPagination::getPageSize
  58. */
  59. public function getPageSize()
  60. {
  61. return $this->getPages()->getPageSize();
  62. }
  63. /**
  64. * @param integer $value number of items in each page
  65. * @see CPagination::setPageSize
  66. */
  67. public function setPageSize($value)
  68. {
  69. $this->getPages()->setPageSize($value);
  70. }
  71. /**
  72. * @return integer total number of items.
  73. * @see CPagination::getItemCount
  74. */
  75. public function getItemCount()
  76. {
  77. return $this->getPages()->getItemCount();
  78. }
  79. /**
  80. * @param integer $value total number of items.
  81. * @see CPagination::setItemCount
  82. */
  83. public function setItemCount($value)
  84. {
  85. $this->getPages()->setItemCount($value);
  86. }
  87. /**
  88. * @return integer number of pages
  89. * @see CPagination::getPageCount
  90. */
  91. public function getPageCount()
  92. {
  93. return $this->getPages()->getPageCount();
  94. }
  95. /**
  96. * @param boolean $recalculate whether to recalculate the current page based on the page size and item count.
  97. * @return integer the zero-based index of the current page. Defaults to 0.
  98. * @see CPagination::getCurrentPage
  99. */
  100. public function getCurrentPage($recalculate=true)
  101. {
  102. return $this->getPages()->getCurrentPage($recalculate);
  103. }
  104. /**
  105. * @param integer $value the zero-based index of the current page.
  106. * @see CPagination::setCurrentPage
  107. */
  108. public function setCurrentPage($value)
  109. {
  110. $this->getPages()->setCurrentPage($value);
  111. }
  112. /**
  113. * Creates the URL suitable for pagination.
  114. * @param integer $page the page that the URL should point to.
  115. * @return string the created URL
  116. * @see CPagination::createPageUrl
  117. */
  118. protected function createPageUrl($page)
  119. {
  120. return $this->getPages()->createPageUrl($this->getController(),$page);
  121. }
  122. }