1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Plugin for views without pagers. |
---|
5 | * |
---|
6 | * @ingroup views_pager_plugins |
---|
7 | */ |
---|
8 | class views_plugin_pager_some extends views_plugin_pager { |
---|
9 | function summary_title() { |
---|
10 | if (!empty($this->options['offset'])) { |
---|
11 | return format_plural($this->options['items_per_page'], '@count item, skip @skip', '@count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); |
---|
12 | } |
---|
13 | return format_plural($this->options['items_per_page'], '@count item', '@count items', array('@count' => $this->options['items_per_page'])); |
---|
14 | } |
---|
15 | |
---|
16 | function option_definition() { |
---|
17 | $options = parent::option_definition(); |
---|
18 | $options['items_per_page'] = array('default' => 10); |
---|
19 | $options['offset'] = array('default' => 0); |
---|
20 | |
---|
21 | return $options; |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * Provide the default form for setting options. |
---|
26 | */ |
---|
27 | function options_form(&$form, &$form_state) { |
---|
28 | $form['items_per_page'] = array( |
---|
29 | '#title' => t('Items to display'), |
---|
30 | '#type' => 'textfield', |
---|
31 | '#description' => t('The number of items to display per page.'), |
---|
32 | '#default_value' => $this->options['items_per_page'], |
---|
33 | ); |
---|
34 | |
---|
35 | $form['offset'] = array( |
---|
36 | '#type' => 'textfield', |
---|
37 | '#title' => t('Offset'), |
---|
38 | '#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed.'), |
---|
39 | '#default_value' => $this->options['offset'], |
---|
40 | ); |
---|
41 | } |
---|
42 | |
---|
43 | function use_pager() { |
---|
44 | return FALSE; |
---|
45 | } |
---|
46 | |
---|
47 | function use_count_query() { |
---|
48 | return FALSE; |
---|
49 | } |
---|
50 | |
---|
51 | function query() { |
---|
52 | $this->view->query->set_limit($this->options['items_per_page']); |
---|
53 | $this->view->query->set_offset($this->options['offset']); |
---|
54 | } |
---|
55 | } |
---|