webform_handler_area_result_pager.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Definition of views_handler_area_result.
  4. *
  5. * Views area handler to display some configurable result summary.
  6. *
  7. * @ingroup views_area_handlers
  8. */
  9. class webform_handler_area_result_pager extends views_handler_area_result {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function option_definition() {
  14. $options = parent::option_definition();
  15. $options['content']['default'] = t('Displaying @start - @end of @total. @items_per_page_links');
  16. $options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
  17. return $options;
  18. }
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function options_form(&$form, &$form_state) {
  23. parent::options_form($form, $form_state);
  24. $form['content']['#description'] .= '<br/>' . t('Plus @items_per_page_links -- the list of links to change the items/page, with prompt');
  25. $form['tokenize'] = array(
  26. '#type' => 'checkbox',
  27. '#title' => t('Use replacement tokens from the first row'),
  28. '#default_value' => $this->options['tokenize'],
  29. );
  30. }
  31. /**
  32. * Find out the information to render.
  33. */
  34. public function render($empty = FALSE) {
  35. $output = parent::render($empty);
  36. if (is_string($output) && isset($this->view->query->pager)) {
  37. $output = str_replace('@items_per_page_links', $this->render_items_per_page($this->view->query->pager), $output);
  38. if ($this->options['tokenize']) {
  39. $output = $this->view->style_plugin->tokenize_value($output, 0);
  40. $output = $this->sanitize_value($output, 'xss_admin');
  41. }
  42. }
  43. return $output;
  44. }
  45. /**
  46. *
  47. */
  48. public function query() {
  49. $view = $this->view;
  50. if (!empty($_GET['items_per_page']) && $_GET['items_per_page'] > 0) {
  51. $view->set_items_per_page($_GET['items_per_page']);
  52. }
  53. elseif (!empty($_GET['items_per_page']) && $_GET['items_per_page'] == 'All') {
  54. $view->set_items_per_page(0);
  55. }
  56. }
  57. /**
  58. *
  59. */
  60. public function render_items_per_page($pager) {
  61. $sanitized_options = array();
  62. if (!empty($pager->options['expose']['items_per_page_options'])) {
  63. $options = explode(',', $pager->options['expose']['items_per_page_options']);
  64. foreach ($options as $option) {
  65. if ($pager->total_items <= intval($option)) {
  66. break;
  67. }
  68. $sanitized_options[intval($option)] = intval($option);
  69. }
  70. if (!empty($sanitized_options) && !empty($pager->options['expose']['items_per_page_options_all']) && !empty($pager->options['expose']['items_per_page_options_all_label'])) {
  71. $sanitized_options[0] = $pager->options['expose']['items_per_page_options_all_label'];
  72. }
  73. $url_query = $_GET;
  74. unset($url_query['q']);
  75. foreach ($sanitized_options as $items_per_page => &$label) {
  76. $selected = $pager->options['items_per_page'] == $items_per_page ||
  77. ($items_per_page == 0 && $pager->total_items < intval($pager->options['items_per_page']));
  78. $label = l($label, $_GET['q'], array(
  79. 'query' => array('items_per_page' => $label) + $url_query,
  80. 'attributes' => array(
  81. 'class' => $selected ? array('selected') : array(),
  82. ),
  83. ));
  84. }
  85. // Drop PHP reference.
  86. unset($label);
  87. // Include CSS needed for 'selected' class.
  88. drupal_add_library('webform', 'admin');
  89. }
  90. return $sanitized_options ? t('Show !links results per page.', array('!links' => implode(' | ', $sanitized_options))) : '';
  91. }
  92. }