Projet

Général

Profil

Paste
Télécharger (3,35 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / views / webform_handler_area_result_pager.inc @ e9f59ce0

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_area_result.
6
 */
7

    
8
/**
9
 * Views area handler to display some configurable result summary.
10
 *
11
 * @ingroup views_area_handlers
12
 */
13
class webform_handler_area_result_pager extends views_handler_area_result {
14

    
15
  function option_definition() {
16
    $options = parent::option_definition();
17
    $options['content']['default'] = t('Displaying @start - @end of @total. @items_per_page_links');
18
    $options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
19
    return $options;
20
  }
21

    
22
  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

    
26
    $form['tokenize'] = array(
27
      '#type' => 'checkbox',
28
      '#title' => t('Use replacement tokens from the first row'),
29
      '#default_value' => $this->options['tokenize'],
30
    );
31
  }
32

    
33

    
34
  /**
35
   * Find out the information to render.
36
   */
37
  function render($empty = FALSE) {
38
    $output = parent::render($empty);
39
    if (is_string($output) && isset($this->view->query->pager)) {
40
      $output = str_replace('@items_per_page_links', $this->render_items_per_page($this->view->query->pager), $output);
41
      if ($this->options['tokenize']) {
42
        $output = $this->view->style_plugin->tokenize_value($output, 0);
43
        $output = $this->sanitize_value($output, 'xss_admin');
44
      }
45
    }
46
    return $output;
47
  }
48

    
49
  function query() {
50
    $view = $this->view;
51
    if (!empty($_GET['items_per_page']) && $_GET['items_per_page'] > 0) {
52
      $view->set_items_per_page($_GET['items_per_page']);
53
    }
54
    elseif (!empty($_GET['items_per_page']) && $_GET['items_per_page'] == 'All') {
55
      $view->set_items_per_page(0);
56
    }
57
  }
58

    
59
  function render_items_per_page($pager) {
60
    $sanitized_options = array();
61
    if (!empty($pager->options['expose']['items_per_page_options'])) {
62
      $options = explode(',', $pager->options['expose']['items_per_page_options']);
63
      foreach ($options as $option) {
64
        if ($pager->total_items <= intval($option)) {
65
          break;
66
        }
67
        $sanitized_options[intval($option)] = intval($option);
68
      }
69
      if (!empty($sanitized_options) && !empty($pager->options['expose']['items_per_page_options_all']) && !empty($pager->options['expose']['items_per_page_options_all_label'])) {
70
        $sanitized_options[0] = $pager->options['expose']['items_per_page_options_all_label'];
71
      }
72
      $url_query = $_GET;
73
      unset($url_query['q']);
74
      foreach ($sanitized_options as $items_per_page => &$label) {
75
        $selected = $pager->options['items_per_page'] == $items_per_page ||
76
                    ($items_per_page == 0 && $pager->total_items < intval($pager->options['items_per_page']));
77
        $label = l($label, $_GET['q'], array('query' => array('items_per_page' => $label) + $url_query,
78
                                             'attributes' => array(
79
                                                'class' => $selected ? array('selected') : array(),
80
                                            )));
81

    
82
      }
83
      unset($label); // Drop PHP reference
84

    
85
      // Include CSS needed for 'selected' class.
86
      drupal_add_library('webform', 'admin');
87
    }
88
    return $sanitized_options ? t('Show !links results per page.', array('!links' => implode(' | ', $sanitized_options))) : '';
89
  }
90

    
91
}