views_plugin_pager.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_pager.
  5. */
  6. /**
  7. * @defgroup views_pager_plugins Views pager plugins
  8. * @{
  9. * @todo.
  10. *
  11. * @see hook_views_plugins()
  12. */
  13. /**
  14. * The base plugin to handle pager.
  15. */
  16. class views_plugin_pager extends views_plugin {
  17. /**
  18. *
  19. */
  20. public $current_page = NULL;
  21. /**
  22. *
  23. */
  24. public $total_items = 0;
  25. /**
  26. * Initialize the plugin.
  27. *
  28. * @param view $view
  29. * The view object.
  30. * @param object $display
  31. * The display handler.
  32. */
  33. public function init(&$view, &$display, $options = array()) {
  34. $this->view = &$view;
  35. $this->display = &$display;
  36. $this->unpack_options($this->options, $options);
  37. }
  38. /**
  39. * Get how many items per page this pager will display.
  40. *
  41. * All but the leanest pagers should probably return a value here, so
  42. * most pagers will not need to override this method.
  43. */
  44. public function get_items_per_page() {
  45. return isset($this->options['items_per_page']) ? (int) $this->options['items_per_page'] : 0;
  46. }
  47. /**
  48. * Set how many items per page this pager will display.
  49. *
  50. * This is mostly used for things that will override the value.
  51. */
  52. public function set_items_per_page($items) {
  53. $this->options['items_per_page'] = (int) $items;
  54. }
  55. /**
  56. * Get the page offset, or how many items to skip.
  57. *
  58. * Even pagers that don't actually page can skip items at the beginning,
  59. * so few pagers will need to override this method.
  60. */
  61. public function get_offset() {
  62. return isset($this->options['offset']) ? (int) $this->options['offset'] : 0;
  63. }
  64. /**
  65. * Set the page offset, or how many items to skip.
  66. */
  67. public function set_offset($offset) {
  68. $this->options['offset'] = (int) $offset;
  69. }
  70. /**
  71. * Get the current page.
  72. *
  73. * If NULL, we do not know what the current page is.
  74. */
  75. public function get_current_page() {
  76. return $this->current_page;
  77. }
  78. /**
  79. * Set the current page.
  80. *
  81. * @param int $number
  82. * If provided, the page number will be set to this. If NOT provided,
  83. * the page number will be set from the global page array.
  84. */
  85. public function set_current_page($number = NULL) {
  86. if (!is_numeric($number) || $number < 0) {
  87. $number = 0;
  88. }
  89. $this->current_page = $number;
  90. }
  91. /**
  92. * Get the total number of items.
  93. *
  94. * If NULL, we do not yet know what the total number of items are.
  95. */
  96. public function get_total_items() {
  97. return $this->total_items;
  98. }
  99. /**
  100. * Get the pager id, if it exists.
  101. */
  102. public function get_pager_id() {
  103. return !empty($this->options['id']) ? $this->options['id'] : 0;
  104. }
  105. /**
  106. * Provide the default form form for validating options.
  107. */
  108. public function options_validate(&$form, &$form_state) {
  109. }
  110. /**
  111. * Provide the default form form for submitting options.
  112. */
  113. public function options_submit(&$form, &$form_state) {
  114. }
  115. /**
  116. * Return a string to display as the clickable title for the
  117. * pager plugin.
  118. */
  119. public function summary_title() {
  120. return t('Unknown');
  121. }
  122. /**
  123. * Determine if this pager actually uses a pager.
  124. *
  125. * Only a couple of very specific pagers will set this to false.
  126. */
  127. public function use_pager() {
  128. return TRUE;
  129. }
  130. /**
  131. * Determine if a pager needs a count query.
  132. *
  133. * If a pager needs a count query, a simple query
  134. */
  135. public function use_count_query() {
  136. return TRUE;
  137. }
  138. /**
  139. * Execute the count query, which will be done just prior to the query
  140. * itself being executed.
  141. */
  142. public function execute_count_query(&$count_query) {
  143. $this->total_items = $count_query->execute()->fetchField();
  144. if (!empty($this->options['offset'])) {
  145. $this->total_items -= $this->options['offset'];
  146. }
  147. $this->update_page_info();
  148. return $this->total_items;
  149. }
  150. /**
  151. * If there are pagers that need global values set, this method can
  152. * be used to set them. It will be called when the count query is run.
  153. */
  154. public function update_page_info() {
  155. }
  156. /**
  157. * Modify the query for paging
  158. *
  159. * This is called during the build phase and can directly modify the query.
  160. */
  161. public function query() {
  162. }
  163. /**
  164. * Perform any needed actions just prior to the query executing.
  165. */
  166. public function pre_execute(&$query) {
  167. }
  168. /**
  169. * Perform any needed actions just after the query executing.
  170. */
  171. public function post_execute(&$result) {
  172. }
  173. /**
  174. * Perform any needed actions just before rendering.
  175. */
  176. public function pre_render(&$result) {
  177. }
  178. /**
  179. * Render the pager.
  180. *
  181. * Called during the view render process, this will render the
  182. * pager.
  183. *
  184. * @param array $input
  185. * Any extra GET parameters that should be retained, such as exposed
  186. * input.
  187. */
  188. public function render($input) {
  189. }
  190. /**
  191. * Determine if there are more records available.
  192. *
  193. * This is primarily used to control the display of a more link.
  194. */
  195. public function has_more_records() {
  196. return $this->get_items_per_page()
  197. && $this->total_items > (intval($this->current_page) + 1) * $this->get_items_per_page();
  198. }
  199. /**
  200. * {@inheritdoc}
  201. */
  202. public function exposed_form_alter(&$form, &$form_state) {
  203. }
  204. /**
  205. * {@inheritdoc}
  206. */
  207. public function exposed_form_validate(&$form, &$form_state) {
  208. }
  209. /**
  210. * {@inheritdoc}
  211. */
  212. public function exposed_form_submit(&$form, &$form_state, &$exclude) {
  213. }
  214. /**
  215. * {@inheritdoc}
  216. */
  217. public function uses_exposed() {
  218. return FALSE;
  219. }
  220. /**
  221. * {@inheritdoc}
  222. */
  223. public function items_per_page_exposed() {
  224. return FALSE;
  225. }
  226. /**
  227. * {@inheritdoc}
  228. */
  229. public function offset_exposed() {
  230. return FALSE;
  231. }
  232. }
  233. /**
  234. * @}
  235. */