pager.class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * ZenTaoPHP的分页类。
  4. * The pager class file of ZenTaoPHP framework.
  5. *
  6. * The author disclaims copyright to this source code. In place of
  7. * a legal notice, here is a blessing:
  8. *
  9. * May you do good and not evil.
  10. * May you find forgiveness for yourself and forgive others.
  11. * May you share freely, never taking more than you give.
  12. */
  13. helper::import(dirname(dirname(__FILE__)) . '/base/pager/pager.class.php');
  14. /**
  15. * pager类.
  16. * Pager class.
  17. *
  18. * @package framework
  19. */
  20. class pager extends basePager
  21. {
  22. /**
  23. * 分页查询起始偏移量。
  24. * offset
  25. *
  26. * @var float
  27. * @access public
  28. */
  29. public $offset = 0;
  30. /**
  31. * 设置分页查询起始偏移量。
  32. * Set offset of paging query.
  33. *
  34. * @param int $offset
  35. * @access public
  36. * @return void
  37. */
  38. public function setOffset($offset)
  39. {
  40. $this->offset = $offset;
  41. }
  42. /**
  43. * 设置模块名。
  44. * Set the $moduleName property.
  45. *
  46. * @access public
  47. * @return void
  48. */
  49. public function setModuleName()
  50. {
  51. /* 如果设置了请求的原始模块名,则把其赋值给$this->moduleName。*/
  52. /* If the original module name of the request is set, assign it to $this->moduleName. */
  53. if(isset($this->app->rawModule))
  54. {
  55. $this->moduleName = $this->app->rawModule;
  56. }
  57. else
  58. {
  59. $this->moduleName = $this->app->getModuleName();
  60. }
  61. }
  62. /**
  63. * 设置方法名。
  64. * Set the $methodName property.
  65. *
  66. * @access public
  67. * @return void
  68. */
  69. public function setMethodName()
  70. {
  71. /* 如果设置了请求的原始方法名,则把其赋值给$this->methodName。*/
  72. /* If the original method name of the request is set, assign it to $this->methodName. */
  73. if(isset($this->app->rawMethod))
  74. {
  75. $this->methodName = $this->app->rawMethod;
  76. }
  77. else
  78. {
  79. $this->methodName = $this->app->getMethodName();
  80. }
  81. }
  82. /**
  83. * 如果设置了请求的原始模块名和方法名,则去掉module参数,以便分页功能生成原始请求的URL而不是转换后的工作流URL。
  84. * If the original module name and method name of the request are set, the module parameter is removed so that
  85. * the paging function generates the URL of the original request instead of the converted workflow URL.
  86. *
  87. * @access public
  88. * @return void
  89. */
  90. public function setParams($params = array())
  91. {
  92. if(isset($this->app->rawParams))
  93. {
  94. parent::setParams($this->app->rawParams);
  95. }
  96. else
  97. {
  98. parent::setParams();
  99. }
  100. /* If the original module name and method name of the request are set, the module parameter is removed. */
  101. if($this->app->isFlow) unset($this->params['module']);
  102. }
  103. /**
  104. * 创建limit语句。
  105. * Create the limit string.
  106. *
  107. * @access public
  108. * @return string
  109. */
  110. public function limit()
  111. {
  112. $limit = '';
  113. if($this->pageTotal > 1) $limit = ' lImiT ' . ($this->offset + ($this->pageID - 1) * $this->recPerPage) . ", $this->recPerPage";
  114. return $limit;
  115. }
  116. /**
  117. * Show pager.
  118. *
  119. * @param string $align
  120. * @param string $type
  121. * @param int $maxRecPerPage
  122. * @access public
  123. * @return void
  124. */
  125. public function show($align = 'right', $type = 'full', $maxRecPerPage = 0)
  126. {
  127. if($type == 'pagerjs')
  128. {
  129. $this->setParams();
  130. $params = $this->params;
  131. foreach($params as $key => $value)
  132. {
  133. if(strtolower($key) == 'recperpage') $params[$key] = '{recPerPage}';
  134. if(strtolower($key) == 'pageid') $params[$key] = '{page}';
  135. }
  136. if($this->recTotal == 0)
  137. {
  138. echo "<div class='pull-right'>" . $this->lang->pager->noRecord . '</div>';
  139. }
  140. else
  141. {
  142. $pageSizeOptions = '';
  143. if($maxRecPerPage)
  144. {
  145. /* Set record per page. */
  146. for($i = 5; $i <= 50; $i += 5) $options[] = $i;
  147. $options = array_merge($options, array(100, 200, 500, 1000, 2000));
  148. $pageSizeOptions = 'data-page-size-options="';
  149. foreach($options as $option)
  150. {
  151. $pageSizeOptions .= "$option,";
  152. if($option >= $maxRecPerPage)
  153. {
  154. $pageSizeOptions = trim($pageSizeOptions, ',') . '"';
  155. break;
  156. }
  157. }
  158. }
  159. global $app, $lang;
  160. $appendApp = '';
  161. $moduleName = $this->moduleName;
  162. if(isset($lang->navGroup->{$moduleName}) and $lang->navGroup->{$moduleName} != $app->tab) $appendApp = "#app={$app->tab}";
  163. echo "<ul class='pager' $pageSizeOptions data-page-cookie='{$this->pageCookie}' data-ride='pager' data-rec-total='{$this->recTotal}' data-rec-per-page='{$this->recPerPage}' data-page='{$this->pageID}' data-link-creator='" . helper::createLink($this->moduleName, $this->methodName, $params) . $appendApp . "'></ul>";
  164. }
  165. }
  166. else
  167. {
  168. parent::show($align, $type);
  169. }
  170. }
  171. }