views_plugin_pager.inc

Definition of views_plugin_pager.

File

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