pager.func.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * Stub file for bootstrap_pager().
  5. */
  6. /**
  7. * Returns HTML for a query pager.
  8. *
  9. * Menu callbacks that display paged query results should call theme('pager') to
  10. * retrieve a pager control so that users can view other results. Format a list
  11. * of nearby pages with additional query results.
  12. *
  13. * @param array $variables
  14. * An associative array containing:
  15. * - tags: An array of labels for the controls in the pager.
  16. * - element: An optional integer to distinguish between multiple pagers on
  17. * one page.
  18. * - parameters: An associative array of query string parameters to append to
  19. * the pager links.
  20. * - quantity: The number of pages in the list.
  21. *
  22. * @return string
  23. * The constructed HTML.
  24. *
  25. * @see theme_pager()
  26. *
  27. * @ingroup theme_functions
  28. */
  29. function bootstrap_pager($variables) {
  30. $output = "";
  31. $items = array();
  32. $tags = $variables['tags'];
  33. $element = $variables['element'];
  34. $parameters = $variables['parameters'];
  35. $quantity = $variables['quantity'];
  36. global $pager_page_array, $pager_total;
  37. // Calculate various markers within this pager piece:
  38. // Middle is used to "center" pages around the current page.
  39. $pager_middle = ceil($quantity / 2);
  40. // Current is the page we are currently paged to.
  41. $pager_current = $pager_page_array[$element] + 1;
  42. // First is the first page listed by this pager piece (re quantity).
  43. $pager_first = $pager_current - $pager_middle + 1;
  44. // Last is the last page listed by this pager piece (re quantity).
  45. $pager_last = $pager_current + $quantity - $pager_middle;
  46. // Max is the maximum page number.
  47. $pager_max = $pager_total[$element];
  48. // Prepare for generation loop.
  49. $i = $pager_first;
  50. if ($pager_last > $pager_max) {
  51. // Adjust "center" if at end of query.
  52. $i = $i + ($pager_max - $pager_last);
  53. $pager_last = $pager_max;
  54. }
  55. if ($i <= 0) {
  56. // Adjust "center" if at start of query.
  57. $pager_last = $pager_last + (1 - $i);
  58. $i = 1;
  59. }
  60. // End of generation loop preparation.
  61. $li_first = theme('pager_first', array(
  62. 'text' => (isset($tags[0]) ? $tags[0] : t('first')),
  63. 'element' => $element,
  64. 'parameters' => $parameters,
  65. ));
  66. $li_previous = theme('pager_previous', array(
  67. 'text' => (isset($tags[1]) ? $tags[1] : t('previous')),
  68. 'element' => $element,
  69. 'interval' => 1,
  70. 'parameters' => $parameters,
  71. ));
  72. $li_next = theme('pager_next', array(
  73. 'text' => (isset($tags[3]) ? $tags[3] : t('next')),
  74. 'element' => $element,
  75. 'interval' => 1,
  76. 'parameters' => $parameters,
  77. ));
  78. $li_last = theme('pager_last', array(
  79. 'text' => (isset($tags[4]) ? $tags[4] : t('last')),
  80. 'element' => $element,
  81. 'parameters' => $parameters,
  82. ));
  83. if ($pager_total[$element] > 1) {
  84. // Only show "first" link if set on components' theme setting
  85. if ($li_first && bootstrap_setting('pager_first_and_last')) {
  86. $items[] = array(
  87. 'class' => array('pager-first'),
  88. 'data' => $li_first,
  89. );
  90. }
  91. if ($li_previous) {
  92. $items[] = array(
  93. 'class' => array('prev'),
  94. 'data' => $li_previous,
  95. );
  96. }
  97. // When there is more than one page, create the pager list.
  98. if ($i != $pager_max) {
  99. if ($i > 1) {
  100. $items[] = array(
  101. 'class' => array('pager-ellipsis', 'disabled'),
  102. 'data' => '<span>…</span>',
  103. );
  104. }
  105. // Now generate the actual pager piece.
  106. for (; $i <= $pager_last && $i <= $pager_max; $i++) {
  107. if ($i < $pager_current) {
  108. $items[] = array(
  109. // 'class' => array('pager-item'),
  110. 'data' => theme('pager_previous', array(
  111. 'text' => $i,
  112. 'element' => $element,
  113. 'interval' => ($pager_current - $i),
  114. 'parameters' => $parameters,
  115. )),
  116. );
  117. }
  118. if ($i == $pager_current) {
  119. $items[] = array(
  120. // Add the active class.
  121. 'class' => array('active'),
  122. 'data' => "<span>$i</span>",
  123. );
  124. }
  125. if ($i > $pager_current) {
  126. $items[] = array(
  127. 'data' => theme('pager_next', array(
  128. 'text' => $i,
  129. 'element' => $element,
  130. 'interval' => ($i - $pager_current),
  131. 'parameters' => $parameters,
  132. )),
  133. );
  134. }
  135. }
  136. if ($i < $pager_max) {
  137. $items[] = array(
  138. 'class' => array('pager-ellipsis', 'disabled'),
  139. 'data' => '<span>…</span>',
  140. );
  141. }
  142. }
  143. // End generation.
  144. if ($li_next) {
  145. $items[] = array(
  146. 'class' => array('next'),
  147. 'data' => $li_next,
  148. );
  149. }
  150. // // Only show "last" link if set on components' theme setting
  151. if ($li_last && bootstrap_setting('pager_first_and_last')) {
  152. $items[] = array(
  153. 'class' => array('pager-last'),
  154. 'data' => $li_last,
  155. );
  156. }
  157. $build = array(
  158. '#theme_wrappers' => array('container__pager'),
  159. '#attributes' => array(
  160. 'class' => array(
  161. 'text-center',
  162. ),
  163. ),
  164. 'pager' => array(
  165. '#theme' => 'item_list',
  166. '#items' => $items,
  167. '#attributes' => array(
  168. 'class' => array('pagination'),
  169. ),
  170. ),
  171. );
  172. return drupal_render($build);
  173. }
  174. return $output;
  175. }