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