views_plugin_pager_some.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_pager_some.
  5. */
  6. /**
  7. * Plugin for views without pagers.
  8. *
  9. * @ingroup views_pager_plugins
  10. */
  11. class views_plugin_pager_some extends views_plugin_pager {
  12. /**
  13. *
  14. */
  15. public function summary_title() {
  16. if (!empty($this->options['offset'])) {
  17. 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']));
  18. }
  19. return format_plural($this->options['items_per_page'], '@count item', '@count items', array('@count' => $this->options['items_per_page']));
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function option_definition() {
  25. $options = parent::option_definition();
  26. $options['items_per_page'] = array('default' => 10);
  27. $options['offset'] = array('default' => 0);
  28. return $options;
  29. }
  30. /**
  31. * Provide the default form for setting options.
  32. */
  33. public function options_form(&$form, &$form_state) {
  34. parent::options_form($form, $form_state);
  35. $pager_text = $this->display->handler->get_pager_text();
  36. $form['items_per_page'] = array(
  37. '#title' => $pager_text['items per page title'],
  38. '#type' => 'textfield',
  39. '#description' => $pager_text['items per page description'],
  40. '#default_value' => $this->options['items_per_page'],
  41. );
  42. $form['offset'] = array(
  43. '#type' => 'textfield',
  44. '#title' => t('Offset'),
  45. '#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.'),
  46. '#default_value' => $this->options['offset'],
  47. );
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function use_pager() {
  53. return FALSE;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function use_count_query() {
  59. return FALSE;
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function query() {
  65. $this->view->query->set_limit($this->options['items_per_page']);
  66. $this->view->query->set_offset($this->options['offset']);
  67. }
  68. }