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