5 * Definition of views_plugin_pager.
9 * @defgroup views_pager_plugins Views pager plugins
13 * @see hook_views_plugins()
17 * The base plugin to handle pager.
19 class views_plugin_pager extends views_plugin {
20 var $current_page = NULL;
24 * Initialize the plugin.
29 * The display handler.
31 function init(&$view, &$display, $options = array()) {
33 $this->display = &$display;
35 $this->unpack_options($this->options, $options);
39 * Get how many items per page this pager will display.
41 * All but the leanest pagers should probably return a value here, so
42 * most pagers will not need to override this method.
44 function get_items_per_page() {
45 return isset($this->options['items_per_page']) ? $this->options['items_per_page'] : 0;
49 * Set how many items per page this pager will display.
51 * This is mostly used for things that will override the value.
53 function set_items_per_page($items) {
54 $this->options['items_per_page'] = $items;
58 * Get the page offset, or how many items to skip.
60 * Even pagers that don't actually page can skip items at the beginning,
61 * so few pagers will need to override this method.
63 function get_offset() {
64 return isset($this->options['offset']) ? $this->options['offset'] : 0;
68 * Set the page offset, or how many items to skip.
70 function set_offset($offset) {
71 $this->options['offset'] = $offset;
75 * Get the current page.
77 * If NULL, we do not know what the current page is.
79 function get_current_page() {
80 return $this->current_page;
84 * Set the current page.
87 * If provided, the page number will be set to this. If NOT provided,
88 * the page number will be set from the global page array.
90 function set_current_page($number = NULL) {
91 if (!is_numeric($number) || $number < 0) {
94 $this->current_page = $number;
98 * Get the total number of items.
100 * If NULL, we do not yet know what the total number of items are.
102 function get_total_items() {
103 return $this->total_items;
107 * Get the pager id, if it exists
109 function get_pager_id() {
110 return !empty($this->options['id']) ? $this->options['id'] : 0;
114 * Provide the default form form for validating options
116 function options_validate(&$form, &$form_state) { }
119 * Provide the default form form for submitting options
121 function options_submit(&$form, &$form_state) { }
124 * Return a string to display as the clickable title for the
127 function summary_title() {
132 * Determine if this pager actually uses a pager.
134 * Only a couple of very specific pagers will set this to false.
136 function use_pager() {
141 * Determine if a pager needs a count query.
143 * If a pager needs a count query, a simple query
145 function use_count_query() {
150 * Execute the count query, which will be done just prior to the query
151 * itself being executed.
153 function execute_count_query(&$count_query) {
154 $this->total_items = $count_query->execute()->fetchField();
155 if (!empty($this->options['offset'])) {
156 $this->total_items -= $this->options['offset'];
159 $this->update_page_info();
160 return $this->total_items;
164 * If there are pagers that need global values set, this method can
165 * be used to set them. It will be called when the count query is run.
167 function update_page_info() {
172 * Modify the query for paging
174 * This is called during the build phase and can directly modify the query.
179 * Perform any needed actions just prior to the query executing.
181 function pre_execute(&$query) { }
184 * Perform any needed actions just after the query executing.
186 function post_execute(&$result) { }
189 * Perform any needed actions just before rendering.
191 function pre_render(&$result) { }
196 * Called during the view render process, this will render the
200 * Any extra GET parameters that should be retained, such as exposed
203 function render($input) { }
206 * Determine if there are more records available.
208 * This is primarily used to control the display of a more link.
210 function has_more_records() {
211 return $this->get_items_per_page()
212 && $this->total_items > (intval($this->current_page) + 1) * $this->get_items_per_page();
215 function exposed_form_alter(&$form, &$form_state) { }
217 function exposed_form_validate(&$form, &$form_state) { }
219 function exposed_form_submit(&$form, &$form_state, &$exclude) { }
221 function uses_exposed() {
225 function items_per_page_exposed() {
229 function offset_exposed() {